0% found this document useful (0 votes)
6 views1 page

Java Loop Control: Continue vs. Break

Uploaded by

givok47282
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Loop Control: Continue vs. Break

Uploaded by

givok47282
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

vs.

in Java Loops

The continue and break statements in Java are both branching statements used within loops
to alter the flow of execution, but they do so in different ways12.

continue: When encountered inside a loop, the continue statement immediately jumps to the
next iteration of the loop, skipping the remaining code in the current iteration2.

Consider the example provided in the sources where a continue statement is used inside a for
loop2:

In this example, when i equals 2, the continue statement is executed, and the loop jumps to
the next iteration, skipping the [Link](i) statement for i=2. Therefore, the output
of this code will be:

break: The break statement, on the other hand, completely terminates the loop when
executed2. The control flow then moves to the code following the loop.

An example demonstrating the use of break is also given in the sources2:

When i is equal to 3, the break statement is triggered, causing the for loop to terminate
immediately. Consequently, the output of this code snippet will be:

In essence, the continue statement is used to skip a specific iteration within a loop, while the
break statement is used to exit the loop entirely.

You might also like