title: The for statement returns before the while statement ends
body: <p>Based on today's date, I have created a code that adds one year to the future.</p>
  <pre><code>val calendarObject = JSONObject()
  val calendarArray = JSONArray()
  
  val currentCalendar = calendar.clone() as Calendar
  
  val futureCalendar = calendar.clone() as Calendar
  futureCalendar.add(Calendar.YEAR, 1)
  
  do {
      val timeFormat = SimpleDateFormat(&quot;yyyyMMdd&quot;, Locale.getDefault()).format(currentCalendar.timeInMillis)
      calendarObject.put(&quot;date&quot;, timeFormat)
      currentCalendar.add(Calendar.DAY_OF_MONTH, 1)
      Log.d(&quot;Activity&quot;, &quot;TEST while $timeFormat ${calendarObject.getString(&quot;date&quot;)}&quot;)
      calendarArray.put(calendarObject)
  } while (currentCalendar.timeInMillis != futureCalendar.timeInMillis)
  
  for (i in 0 until calendarArray.length()) {
      Log.d(&quot;Activity&quot;, &quot;TEST for ${calendarArray.getJSONObject(i)}&quot;)
  }
  
  inputObject.put(&quot;calendar&quot;, calendarArray)
  </code></pre>
  <p>The log taken with <code>TEST while</code> shows that the date is added day by day.
  <a href="https://i.stack.imgur.com/8Fwtb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Fwtb.png" alt="enter image description here" /></a></p>
  <p>However, up to two <code>TEST for</code> outputs, and the same date is included in the saved json format file.
  <a href="https://i.stack.imgur.com/POd65.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/POd65.png" alt="enter image description here" /></a></p>
  <p>Why is this happening and is there a way to fix it?</p>