Scala Break statement

Category : Scala | Sub Category : Scala Programs | By Runner Dev Last updated: 2020-10-08 10:38:07 Viewed : 216


Scala Break statement

 Break syntax as follows

          break

    import the below package in the file 

    import scala.util.control.Breaks._

Example:

Following example illustrates about Scala break statement

Save the file as −  ScalaBreak.scala. 

ScalaBreak.scala //File name

package runnerdev

import scala.util.control.Breaks._ 

object ScalaBreak {

  def main(args: Array[String]) {

    for (i <- 1 to 3) {

      breakable {

        for (j <- 1 to 3) {

          if (i == 2 & j == 2)

            break

          println(i + "  " + j)

        }

      }

    }

  } 

} 

compile and run the above example as follows 

scala> scalac ScalaBreak.scala

scala> scala ScalaBreak 

OutPut:

1  1

1  2

1  3

2  1

3  1

3  2

3  3

Search
Sub-Categories
Related Articles

Leave a Comment: