Scala Break statement

Category : Scala | Sub Category : Scala Programs | By Prasad Bonam Last updated: 2020-10-08 05:08:07 Viewed : 517


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
Related Articles

Leave a Comment: