Download Scala Tutorial (PDF Version) - Tutorials Point
Download Scala Tutorial (PDF Version) - Tutorials Point
Download Scala Tutorial (PDF Version) - Tutorials Point
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
When the above code is compiled and executed, it produces the following result:<br />
C:/>scalac Test.scala<br />
C:/>scala Test<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 />
value of a: 7<br />
value of a: 8<br />
value of a: 9<br />
C:/><br />
You can use multiple ranges separated by semicolon (;) within a for loop and in that case loop will iterate through<br />
all the possible computations of the given ranges. Following is an example of using just two ranges, you can use<br />
more than two ranges as well.<br />
object Test {<br />
def main(args: Array[String]) {<br />
var a = 0;<br />
var b = 0;<br />
// for loop execution with a range<br />
for( a scala Test<br />
Value of a: 1<br />
Value of b: 1<br />
Value of a: 1<br />
Value of b: 2<br />
Value of a: 1<br />
Value of b: 3<br />
Value of a: 2<br />
Value of b: 1<br />
Value of a: 2<br />
Value of b: 2<br />
Value of a: 2<br />
Value of b: 3<br />
Value of a: 3<br />
Value of b: 1<br />
Value of a: 3<br />
Value of b: 2<br />
Value of a: 3<br />
Value of b: 3<br />
C:/><br />
The for Loop with Collections<br />
The syntax of a for loop with collection is as follows:<br />
TUTORIALS POINT<br />
Simply Easy Learning