Scala While Loop

In Scala, break out of a loop needs to be implemented with

import scala.util.control.Breaks._
breakable {

}

block code

While loop statement example.

import scala.util.control.Breaks._
var tl=Seq(1,2,3,4,5) 
var counter=0
breakable {
while (true)
  {
        if (counter>=tl.length)
          break
        counter+=1
  }
}

Last updated