break statement in c code example
Example 1: how to break a loop in c
// The code will print your number 10 times if x <= 100
int x = 120;
for (int i = 0; i < 10; i++)
{
if (x > 100)
// Note: if multiple for loops: breaks the superficial one
break;
else
printf("%i\n", x);
}
Example 2: for loop continue c
a = 0;
do {
if( a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}
printf("value of a: %d\n", a);
a++;
} while( a < 20 );