title: Populate a list in Kotlin with a for loop
body: <p>It's been a while that I just started to learn how to develop in Kotlin. 
  There is this thing that I am working on, I am trying to parse a list into another type of list. Basically they are the same thing but with different names. But when I try to populate the new list with the data that I get from the list given as parameter in the function the list only gets populated with the first object. </p>
  
  <p>Here is my function:</p>
  
  <pre><code>fun convertRoomClass(course: List&lt;Course&gt;) : List&lt;Courses&gt; {
  
      lateinit var list : List&lt;Courses&gt;
  
  
      course.forEach {
          val id = it.pathID
          val name = it.pathName
          val desc = it.pathDescription
  
          val crs : Courses = Courses(id, name!!, desc!!)
  
           list = listOf(crs)
      }
  
      return list
  }
  </code></pre>