Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Scala<br />
}<br />
Here, the List variable is a collection type having a list of elements and for loop iterate<br />
through all the elements returning one element in x variable at a time.<br />
Try the following example program to understand loop with a collection of numbers. Here we<br />
created this collection using List(). We will study collections in a separate chapter. Loop<br />
control statements (for statement) in Scala Programming Language.<br />
object Demo {<br />
def main(args: Array[String]) {<br />
var a = 0;<br />
val numList = List(1,2,3,4,5,6);<br />
}<br />
}<br />
// for loop execution with a collection<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 />
value of a: 5<br />
value of a: 6<br />
Syntax: for loop with Filters<br />
63