+ 2

for(int x=10; x<=40; x=x+10) { if(x == 30) { continue; } System.out.println(x); }

Help me to explain this program I can't understand continue statement

5th Nov 2019, 3:26 AM
Minhaj Haider
Minhaj Haider - avatar
3 RĂ©ponses
+ 1
* `continue` takes you back to the beginning of the loop. The first statement inside the loop body will be executed next. for(int x = 10; x <= 40; x = x + 10) { if(x == 30) ←← { ↑ continue; →→ } System.out.println(x); } * `break` takes you out of the loop even when the loop condition still satisfies. The first statement following the for loop body will be executed next. for(int x = 10; x <= 40; x = x + 10) { if(x == 30) { break; →→→→→→→→→→ } ↓ System.out.println(x); ↓ } ↓ System.out.println("Done!");←←
5th Nov 2019, 4:58 AM
Ipang
0
continue just means do not do anything and go back to the start to execute the next statement. So until x=30, 10 20 is printed and when x=30 it again goes to for loop and now x becomes 40 which is printed. So your output would be 10 20 40
5th Nov 2019, 3:48 AM
Avinesh
Avinesh - avatar
0
Break means come out of the loop and continue means stay in the loop.
5th Nov 2019, 3:49 AM
Avinesh
Avinesh - avatar