exit loop 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: exit loop c
#include <stdio.h>
int main () {
for (int i = 1; i <= 100; i++)
{
if (i == 5)
{
//use break, same as c#
break;
}
}
return 0;
}