How to create an infinite loop in Scala

1 Answer

0 votes
object MyClass {
     def main(args: Array[String]): Unit = {
            var x = 100;
      
            while(true) { // infinite loop
                 println("x = " + x);
            }
    }
}
  
  
  
  
        
/*
run:
        
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
x = 100
...
 
*/

 



answered May 31, 2021 by avibootz
edited Apr 10 by avibootz
...