Home »
Code Examples »
Scala Code Examples
Scala - Demonstrate the 'break' statement in 'while' loop Code Example
The code for Demonstrate the 'break' statement in 'while' loop
// Scala program to demonstrate "break" statement
// in "while" loop.
// Importing package
import scala.util.control.Breaks._
object Sample {
def main(args: Array[String]) {
var cnt:Int=0;
cnt=1;
breakable
{
while(cnt<=5)
{
printf("%d ",cnt);
cnt=cnt+1;
if(cnt==3)
break;
}
}
println();
}
}
/*
Output:
1 2
*/
Code by IncludeHelp,
on August 12, 2022 23:39