How exactly do the ''break'' and ''continue'' loop operations work with the for and while loops in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How exactly do the ''break'' and ''continue'' loop operations work with the for and while loops in Java?

I'm trying to practice definite and indefinite loops in Java, but the ''break'' and '' continue'' loop operations keep tripping me.

15th Oct 2016, 4:18 PM
lash-1K
3 Answers
+ 3
example 1 below: int count10 = 0; // initial value while(true){ // infinite loop count10++; if(count10 == 10) break; // jumps out of loop } Example 2 below: for(int i = 1; i <= 100; i++){ // count from 1 - 100 if(i % 2 != 0) continue; System.out.println("even number: "+ i); } The example above basically states if the number is odd then skip the remainder of the loop body and go to next iteration. However if its not odd then print the even number.
15th Oct 2016, 11:33 PM
Ousmane Diaw
0
Thanks
15th Oct 2016, 11:36 PM
lash-1K
0
Hope it has helped. Just play around with it and you shall get the hang of it in no time!.
15th Oct 2016, 11:37 PM
Ousmane Diaw