Now more and more found themselves before the white school, are almost graduating, but even the most basic C language is forgotten clean! Hurry up and fill it up!!
In a nutshell, break jumps out of the current loop body (or switch), and then executes the statement below the loop, and continue ends the loop, does not execute the statement that is not yet executed under the loop body, and then makes the next loop judgment.
The professional understanding of the book is that the break statement can be exited from the inner loop or the switch statement. The continue statement can only appear in the for, while, do loops. (Feel like you don't understand, or see examples)
#include <stdio.h> int main (void) { int flag=0; for (int j=0; J <2; J + +) { if (j==0) { switch (j) {case 0: continue; } flag=1; } } printf ("flag:%d\n", flag);}
Output flag:0 Replace the continue with a break; the output flag:1
#include <stdio.h> void Main () { int flag = 0; int j = 0; for (J=0; J <2; J + +) { if (j==0) { if (j==0) { continue; } flag=1; } } printf ("flag:%d\n", flag);}
Without a switch, break only works on the loop body, so the result of break and Continue is flag:0
Another switch example, will not believe and forget!
#include <stdio.h>#include<string.h>intMain () {Chari; for(i=0;i<5; i++){ Switch(i) { Case 0: printf ("i=%d\n", i); Break; Case 1: printf ("i=%d\n", i); Break; Case 2: printf ("i=%d\n", i);Continue;p rintf ("ok\n"); Case 3: printf ("i=%d\n", i); Break; default: printf ("errp\n"); } printf ("lalala\n"); } getch (); }
The Continue and Lalala in the results are not output, and the break is output.
C_continue and break