C language introductory tutorial -8 loop control statements
Loop control statements are usually used in conjunction with if. Use an if condition to break the loop (break)/ skip the loop (continue)
Example:
#include <stdio.h>
int main (a)
{
int i;
for(i=1; i<=5; i++) {
if(i==3) continue; // Skip this loop if it is 3
else printf("%d\n", i);
}
return 0;
}
Copy the code
Running results:
#include <stdio.h>
int main (a)
{
int i;
for(i=1; i<=5; i++) {
if(i==3) break; // If it is 3, break the loop
else printf("%d\n", i);
}
return 0;
}
Copy the code
Running results:
We can copy the code to our own compiler and analyze it carefully.