28.08.2016 Views

scala_tutorial

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

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

Scala<br />

while(condition)<br />

{<br />

Conditional code;<br />

}<br />

Condition<br />

If condition<br />

is true<br />

Conditional<br />

Code<br />

If Condition<br />

is false<br />

Here, key point of the while loop is that the loop might not ever run. When the condition is<br />

tested and the result is false, the loop body will be skipped and the first statement after the<br />

while loop will be executed.<br />

Try the following example program to understand loop control statements (while statement)<br />

in Scala Programming Language.<br />

object Demo {<br />

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

// Local variable declaration:<br />

var a = 10;<br />

// while loop execution<br />

while( a < 20 ){<br />

println( "Value of a: " + a );<br />

a = a + 1;<br />

56

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

Saved successfully!

Ooh no, something went wrong!