94
Scala Break
Break is used to break a loop or program execution. It skips the current execution. Inside inner loop it breaks the execution of inner loop.
In scala, there is no break statement but you can do it by using break method and by importing scala.util.control.Breaks._ package. Let’s see an example.
Scala Break Example
Output:
1 3 5
Scala Break Example: Break inner Loop
You can use break statement to terminate execution of inner loop in nested loop.
Let’s see an example.
Output:
1 1 1 2 1 3 2 1 3 1 3 2 3 3
Next TopicScala comments