Repeat while a condition remains true.

While Loops

WhileLoop.scala
object Main {
  def main(args: Array[String]): Unit = {
    val limit = 
    var count = 0
    var total = 0

    while (count < limit) {
      count = count + 1
      total = total + count
    }

    println("limit=" + limit)
    println("count=" + count)
    println("total=" + total)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val limit = 
    var count = 0
    var total = 0

    while (count < limit) {
      count = count + 1
      total = total + count
    }

    println("limit=" + limit)
    println("count=" + count)
    println("total=" + total)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val limit = 
    var count = 0
    var total = 0

    while (count < limit) {
      count = count + 1
      total = total + count
    }

    println("limit=" + limit)
    println("count=" + count)
    println("total=" + total)
  }
}
while-loop A while loop checks its condition before each pass. Keep loop limits small and clear.