0
Can't we use break before println??
3 ответов
+ 3
If you mean in loop, answer is no.
break statement would skip whole loop.
Thus everything would have been executed after break in the (innermost) loop were skipped.
+ 9
• Use 'break' statement to come out of the loop instantly. Whenever a break statement is encountered inside a loop, the control directly comes out of loop and the loop gets terminated for rest of the iterations.
For example:
for (int i = 0; i < 5; i++) {
if (i == 3) {
break; // breaking the loop
}
}
+ 7
In loops, you can use break keyword wherever you want. It depends upon ur requirement.
For ex ,
int I = 0;
while (True){
I = I + 1;
if ( I > 10 ) {
break;
}
}
System.out.println ("Loop breaked");