09.10.2014 Views

Download Scala Tutorial (PDF Version) - Tutorials Point

Download Scala Tutorial (PDF Version) - Tutorials Point

Download Scala Tutorial (PDF Version) - Tutorials Point

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

value of a: 2<br />

value of a: 4<br />

value of a: 5<br />

value of a: 6<br />

value of a: 7<br />

C:/><br />

Loop Control Statements:<br />

Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic<br />

objects that were created in that scope are destroyed. As such, <strong>Scala</strong> does not support<br />

break or continue statement like Java does, but starting from <strong>Scala</strong> version 2.8, there is a way to break the loops.<br />

Click the following links to check the detail.<br />

Control Statement<br />

break statement<br />

Description<br />

Terminates the loop statement and transfers execution to the statement<br />

immediately following the loop.<br />

break statement<br />

As such there is no built-in break statement available in <strong>Scala</strong>, but if you are running <strong>Scala</strong> version 2.8, then there is<br />

a way to use break statement. When the break statement is encountered inside a loop, the loop is immediately<br />

terminated and program control resumes at the next statement following the loop.<br />

Syntax:<br />

The syntax of a break statement is bit unusual but it works:<br />

// import following package<br />

import scala.util.control._<br />

// create a Breaks object as follows<br />

val loop = new Breaks;<br />

// Keep the loop inside breakable as follows<br />

loop.breakable{<br />

// Loop will go here<br />

for(...){<br />

....<br />

// Break will go here<br />

loop.break;<br />

}<br />

}<br />

TUTORIALS POINT<br />

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!