Scala - Demonstrate nested 'while' loop Code Example

The code for Demonstrate nested 'while' loop

//Scala program to demonstrate nested "while" loop.

object Sample {  
  def main(args: Array[String]) {  
    var cnt1:Int=0;
    var cnt2:Int=0;
    
    cnt1=2;
    while(cnt1<=5)
    {
      cnt2=1;
      while(cnt2<=10)
      {
        printf("%d ",(cnt1*cnt2));
        cnt2=cnt2+1;
      }
      cnt1=cnt1+1;
      println();
    }
  }
} 


/*
Output:
2 4 6 8 10 12 14 16 18 20 
3 6 9 12 15 18 21 24 27 30 
4 8 12 16 20 24 28 32 36 40 
5 10 15 20 25 30 35 40 45 50 
*/
Code by IncludeHelp, on August 12, 2022 23:37

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.