title: How to "convert" while loop in a recursive function
body: <p>I am starting with Scala and am having a hard time thinking functionally.</p>
  
  <p>I have the following variables:</p>
  
  <pre><code>val dateTimeBegin = Calendar.getInstance()
  dateTimeBegin.set(2016, Calendar.MAY, 25, 12, 0, 0)
  val dateTimeEnd = Calendar.getInstance()
  dateTimeEnd.set(2016, Calendar.MAY, 25, 16, 0, 0)
  var slotsString = List[String]()
  var slots = List[Calendar]()
  </code></pre>
  
  <p>Then, I wrote this while loop:</p>
  
  <pre><code>while (dateTimeBegin.getTime().compareTo(dateTimeEnd.getTime()) == -1) {
    slotsString = dateTimeBegin.getTime().toString() :: slotsString
    dateTimeBegin.add(Calendar.MINUTE, 50)
  }
  </code></pre>
  
  <p>It basically picks the dateTimeBegin and dateTimeEnd and creates slots of 50 minutes.</p>
  
  <p>This is the output that the while loop gives:</p>
  
  <p>Wed May 25 12:00:00 WEST 2016
  Wed May 25 12:50:00 WEST 2016
  Wed May 25 13:40:00 WEST 2016
  Wed May 25 14:30:00 WEST 2016
  Wed May 25 15:20:00 WEST 2016</p>
  
  <p>However, I know that this is not the correct way to program in Scala and I should use a recursive function.
  I tried to write this function:</p>
  
  <pre><code>def fillSlots(l: List[String], cB: Calendar, cE: Calendar): List[String] = {
      var s = List[String]()
  
      if (cB.getTime().compareTo(cE.getTime()) == -1) {
        s = cB.getTime().toString() :: s
        cB.add(Calendar.MINUTE, 50)
        fillSlots(s, cB, cE)
      } else {
        return s
      }
    }
  </code></pre>
  
  <p>But the function doesn't return anything.</p>
  
  <p>Can anyone tell me what am I doing wrong?</p>