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.
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)
+ 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?
+ 3
Thanks.
0
continue skips everything remaining in the loop and restarts it from the top