Break & Continue
There are many scenarios in programming when you have to exit or restart a loop based upon a certain condition or scenario.
{
name : Main
for : {
range : (Int i = 1, 7)
if : {
condition : ${ i == 5 }
println("Breaking the loop")
break
}
println(i)
}
println("Outside the Loop!")
}OUTPUT :
Now, let's see how 'continue' keyword. It is used to shift the control flow of program to the starting of the loop. See the below sample code for it:
OUTPUT :
Last updated