...

Cloud Computing - SCALA

Back to Course

Lesson Description


Lession - #682 SCALA Loop Statement


SCALA Loop

This section takes you through the loop control structures in Scala programming language.

There might be a circumstance, when you want to execute a block of code a few number of times. By and large, statement are executed successively: The first statement in a function is executed first, followed continuously, etc.

Programming language give different control structures that consider more confounded/complex execution ways.

A loop statement permits us to execute an assertion or grou of statement on numerous occasions and following is the general type of a loop statement in the majority of the programming language −

1. while loop
Repeates an assertion or group of statement while a given condition is valid. It tests the condition prior to executing the loop body.

2. do-while loop
Like while statement, then again, actually it tests the condition toward the finish of the loop body.

3. for loop
Executes a sequence of statement on numerous occasions and contracts the code that deals with the loop variable.

loop Control Statements

loop control statement change execution from its not unexpected set. Whenever execution leaves a scope, all programmed objects that were made in that extension are destroyed. As such Scala doesn't uphold/support break or proceed with statement like Java does yet beginning from Scala version 2.8, there is a method for breaking the loops. Click the following connects to actually look at the detail.
Control Statement and Description 1. break statement
Ends the loop statement and moves execution to the assertion immediately following the loop.
The infinite Loop

A loop turns into a infinite loop assuming a condition never turns out to be false. if you are utilizing Scala, the while loop is the most effective way to execute endless loop.

The following system executes infinite loop.

Model
object Demo {
   def main(args: Array[String]>
{ var a = 10; // A limitless loop. while( valid >
{ println( "value of a: " + a >
; } } }

Save the above program in Demo.scala. The following orders are utilized to compile and execute this program.