C: The Continue,break,goto,return of several methods of getting out of circulation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.