C++ Break and Continue

In C++, the break and continue statements allow for better control of loops, enabling you to exit loops early or skip specific iterations.

Tutorials dojo strip

Break Statement

The break statement immediately stops a loop when a specified condition is met, preventing further execution of remaining iterations.

Example: Exiting a Loop When a Condition Is Met

C++

Output:

C++

The loop stops once speed reaches 4, preventing further execution.

Continue Statement

The continue statement skips the current iteration when a condition is met and proceeds to the next loop iteration.

Example: Skipping a Specific Value

C++

Output:

C++

Notice that gear 4 is missing, as it was skipped.

Using Break and Continue in While Loops

Example: Breaking Out of a while Loop

C++

Example: Using continue in a while Loop

C++
Tutorials dojo strip