Scala - Print numbers from 1 to 10 using while loop Code Example

The code for Print numbers from 1 to 10 using while loop

// Scala program to demonstrate "while" loop to 
// print numbers from 1 to 10

object Sample {  
  def main(args: Array[String]) {  
    var cnt:Int=0
    
    cnt=1; //Counter variable initialization.
    while(cnt<=10)
    {
      printf("%d ",cnt);
      cnt=cnt+1; //Counter variable updation
    }
    println()
  }
}  


/*
Output:
1 2 3 4 5 6 7 8 9 10 
*/
Code by IncludeHelp, on August 12, 2022 23:30

Comments and Discussions!

Load comments ↻






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