C break and continue
break and continue are two keywords that used in loops. They control the flow inside the loops. Below shows how these keywords work inside a block of code:
// break
while (condition1) {
statements...;
if (condition2)
break;
statements...;
}
// continue
while (condition1) {
statements...;
if (condition2)
continue;
statements...;
}
The break statement is used to skip a certain condition in a loop, discard the statements below the break statement and end the loop. For example, the loop continues to execute normally in the above code until the condition increases to condition2, it discards the “statements…” below the break statement and ends the loop on condition2.
Just as the break statement, the continue statement skips a certain condition in a loop and discards the statement below the continue statement. The difference from the break statement is that the continue statement continues to executed the loop once the specified condition is skipped. For example, the loop continues to execute normally in the above code until the condition increases to condiion2, it discards the “statements…” below the continue statement and continues the execution at condition3.
There are no posts related to C break and continue.