Continue? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Continue?

If continue is meant to continue loop if certain conditions are true, then why would we need it? as the loop will still continue wothout it?. Please give an example. Thanks.

19th Mar 2017, 7:30 AM
Meharban Singh
Meharban Singh - avatar
4 Answers
+ 14
continue works as skip. if a certain condition is satisfied, then the current iteration will be skipped. For example, for(int i=1; i<=5; i++){ if(i==4) continue; System.out.print(i); } This code will print 1 2 3 5 (because 4 has been skipped here)
19th Mar 2017, 8:51 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
@Luka, As far as I can tell by reading this post, continue is used to skip some values between the start and end point. Am I correct?
19th Mar 2017, 7:53 AM
Meharban Singh
Meharban Singh - avatar
+ 3
Thanks.
19th Mar 2017, 8:01 AM
Meharban Singh
Meharban Singh - avatar
0
continue skips everything remaining in the loop and restarts it from the top
19th Mar 2017, 1:25 PM
LordHill
LordHill - avatar