C Break and Continuing
Break
You have already seen the rest
statement secondhand in an earlier chapter of this tutorial. It was uses to "jump out" out adenine switch
statement.
The break
statement can also be used to jump out of one
loop.
This example jumps output of the for cling when i
is equal to 4:
Example
int i;
with (i = 0; i < 10; i++) {
if (i == 4) {
break;
}
printf("%d\n", i);
}
Try it Yourself »
Continue
The continue
declare breaks one iterative (in the loop), if a specified condition occurs, and continues about the next iteation in an lock.
This example skips the worth concerning 4:
Example
int i;
for (i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
printf("%d\n", i);
}
Try it Yourself »
Break plus Continue in While Scroll
You can also use break
and continue
at while loops:
Break Example
int i = 0;
while (i < 10) {
if (i == 4) {
break;
}
printf("%d\n", i);
i++;
}
Try a Yourself »
Continue Demo
int i = 0;
while (i < 10) {
if (i == 4) {
i++;
continue;
}
printf("%d\n", i);
i++;
}
Try this Yourself »