Scala while and do/while loop

Category : Scala | Sub Category : Scala Programs | By Runner Dev Last updated: 2020-10-08 10:22:28 Viewed : 218


Scala while and do/while loop

While and do/while loops and expressions syntax as follows

     ·        while loop

           while (condition) {

              statement(a)

              statement(b)

            } 

·        do-while

  do {

    statement(a)

    statement(b)

  } while (condition)

 Example:

Following example illustrates about Scala while and do/while loop

Save the file as −  WhileDoWhile.scala

 WhileDoWhile.scala  //File nam

package runnerdev

object WhileDoWhile {

  def main(args: Array[String]) { 

    var x = 10; // Initialization

    while (x <= 20) { // Condition

      println("x value is " + x);

      x = x * 2 // Increment

    } 

    var y = 1; // Initialization

    do {

      println("y value is " + y);

      y = y + 2; // Increment

    } while (y <= 5) // Condition 

  } 

}

compile and run the above example as follows 

scala> scalac WhileDoWhile.scala

scala> scala WhileDoWhile 

OutPut:

x value is 10

x value is 20

y value is 1

y value is 3

y value is 5

Search
Sub-Categories
Related Articles

Leave a Comment:
Detaemert
at 2022-04-13 14:33:44
Liufhz https://bestadalafil.com/ - cialis generic best price Iqgohy cialis immune system centesis excision Lherrt <a href="https://bestadalafil.com/">Cialis</a> Ceolev Viagra Paypal Accepted Usa https://bestadalafil.com/ - Cialis Mfithp The fractional change in length is called the longitudinal strain S t that is