WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Scala - Loop Statements


In Scala tutorial loop statement allows us to execute a statement or group of statements multiple times

Scala programming language provides the following types of loops to handle looping requirements.

Sr.No Loop Type & Description
1

while loop

Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

2

do-while loop

Like a while statement, except that it tests the condition at the end of the loop body.

3

for loop

Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

Output:

1
2
3
4
5
6
7
8
9
10

Loop Control Statements

Sr.No Control Statement & Description
1

break statement

Terminates the loop statement and transfers execution to the statement immediately following the loop.

The infinite Loop

A loop becomes an infinite loop if a condition never becomes false

example
object Demo {
   def main(args: Array[String]) {
      var a = 10;
      
      // An infinite loop.
      while( true ){
         println( "Value of a: " + a );
      }
   }
}
Value of a: 10
Value of a: 10
Value of a: 10
Value of a: 10
…………….