0

Can't we use break before println??

12th Feb 2019, 4:45 AM
ayush dhakate
ayush dhakate - avatar
3 odpowiedzi
+ 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.
12th Feb 2019, 6:22 AM
Seb TheS
Seb TheS - avatar
+ 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 } }
12th Feb 2019, 9:12 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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");
12th Feb 2019, 4:49 AM
Arushi Singhania
Arushi Singhania - avatar