Java Break /Continue
Break and Continue
special key words that can be used in loops
break: exits the loop regardless of the condition.
EXAMPLE:
for (int i=0;i<10; i++){
if (i==4){
break;
}
System .out.prinln(i);
}
continue: skips the rest the loop's. Continue expecting the loop as if we finished executing the body.
-for loop: execute change
-while and do while loops: check condition.
Example:
for(int i=0; i<=10; i++){
if (i==4){
continue;
}
System.out.println(i);
}
Comments
Post a Comment