Several methods to get out of the circulation structure: Continue,break,goto,return
A: Continue end of the cycle, directly into the next cycle
int Main (intconstChar * argv[]) { for (int0 ; j<; J + +) {if (j>5) { continue; } printf ("%d\n", J); } return 0 ;}
Printing results:
0
1
2
3
4
5
Two: Break ends the entire loop structure.
intMainintargcConst Char*argv[]) { for(intj =0; j<Ten; J + +) {printf ("%d\n", J); if(j==5) { Break; }} printf ("Hello, world!\n."); return 0;}
Printing results:
0
1
2
3
4
5
Hello, world!.
Three: Goto ends the entire loop and implements a GOTO definition statement.
code example:
#include <stdio.h>intMainintargcConst Char*argv[]) { for(intj =0; j<Ten; J + +) {printf ("%d\n", J); if(j==5) { GotoPrintname; }} printname:printf ("My name is FS"); printf ("Hello, world!\n."); return 0;}
Printing results:
0
1
2
3
4
5
My name is Fshello, world!
Four: Ends the return value of the function returned by the entire function.
intMainintargcConst Char*argv[]) { for(intj =0; j<Ten; J + +) { if(j>5) { return 0; } printf ("%d\n", J); } return 0;}
Printing results:
0
1
2
3
4
5
It is important to note that:
1.continue,break only works on the current loop and does not work on the outer loop
2.goto is the ability to jump directly to the line of a specified function and continue executing the statement below the specified function.
3.return is the direct End Function return function value, the loop will of course end.
C: The Continue,break,goto,return of several methods of getting out of circulation