28.08.2016 Views

scala_tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Scala<br />

object Demo {<br />

def main(args: Array[String]) {<br />

var a = 0;<br />

val numList = List(1,2,3,4,5,6,7,8,9,10);<br />

val loop = new Breaks;<br />

loop.breakable {<br />

for( a <strong>scala</strong>c Demo.<strong>scala</strong><br />

\><strong>scala</strong> Demo<br />

Output<br />

Value of a: 1<br />

Value of a: 2<br />

Value of a: 3<br />

Value of a: 4<br />

After the loop<br />

Breaking Nested Loops<br />

Existing break has an issue while using for nested loops. Just in case to use break for nested<br />

loops, follow this method. This is an example program for breaking nested loops.<br />

68

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!