Break and Continue Statement: Infinite Loop Situation

What's the difference between break and continue statement? How will it help the infinite loop situation?

© SolutionLibrary Inc. solutionlibary.com 9836dcf9d7 https://solutionlibrary.com/computer-science/software-development/break-and-continue-statement-infinite-loop-situation-7g44

Solution Preview

...nes inside the loop.

int i;
for (i=0;i<5i++)
{
if (i==1)
continue;
System.out.println(i);
if (i==3)
break;
}

This code will print 0, 2, 3, But 1 will not be printed.

In the above code, the break statement is not letting the i value to reach 4, as when the i reaches 3 the second 'if' condition makes the 'for' loop exit.

When the i becomes 1, the continue statement makes the rest of the statement from the ...