title: How to create variables in a for-loop with Kotlin
body: <p>Given a maximum list size in parameter <code>size</code> and total amount of elements in parameter <code>elements</code>, I need to create a list of lists. What is the syntax for creating variables in <code>for</code> loops in Kotlin?</p>
  
  <p>The way I'm thinking of going about this is to declare and create lists before elements are added to a list. Then, when a list has reached full capacity, it is switched out for the next list that is empty.</p>
  
  <p>Here is the half-baked code:</p>
  
  <pre><code>fun listOfLists(size: Int, vararg elements: String): List&lt;List&lt;String&gt;&gt; {
      var amountOfElements = elements.size
      var currentSubList: List&lt;String&gt; = mutableListOf&lt;String&gt;()
      val numberOfLists: Int = amountOfElements / size + 1
  
      for (n in 0..numberOfLists) {
          // Code for creating the total number of lists needed
      }
  
      for (e in elements) {
          if (amountOfElements % size == 0) {
              // Code for switching lists
          }
          amountOfElements--
      }
  </code></pre>