break and continue
break exits its targeted loop. continue skips the rest of the current iteration and advances to the next iteration.
Skipping an item and ending the whole search are different decisions.
See the mechanism
0noneFollow one example
Zero is skipped with continue. The next value, 4, prints. At 6, break ends the loop, so the later 2 is never visited. In a for loop, continue still reaches the update step. In a while loop, ensure the skipped path does not bypass the only update and accidentally prevent termination.
Predict, change and check
Predict: If break becomes continue in the second condition, will 2 be printed?
Test your explanation: Make that replacement and compare the output. Explain which item was skipped and whether the loop ended.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
Know which execution region changes
break exits the selected loop or switch. continue skips the remainder of the current loop iteration and proceeds to the loop's next-step behavior. Neither automatically returns from the enclosing function. A guard inside a loop can skip one invalid record without abandoning all later records.
Nested loops require a clear target for control flow. Labels exist, but a small extracted function can sometimes make the stopping rule easier to review. Test an invalid first item, an invalid middle item and a valid later item to distinguish 'skip one' from 'stop everything'.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.