5.4 Break and Continue

The break statement stops the execution of the current construct and skips to the constructs end. As seen in Section 5.3 this is most often used within a switch statement, but it's also used in various loops statements.

The continue statement is used within loops to stop the execution of the current loop and skip to the condition check.

See the following code for an exmaple of how continue works:

    #include <stdio.h>
    
    int main()
    {
        int x;
    
        for (x = 1; x <= 6; x++)
        {
            if (x == 3)
                continue;
            printf("x is %d\n", x);
        }
        
        return 0;
    }
    
   

When this program is executed, the following will be it's ouput. Notice how there's no "x is 3".

    x is 1
    x is 2
    x is 4
    x is 5
    x is 6
    
   

This, and other documents, can be downloaded from http://opencbp.sourceforge.net/.

For questions about the Open C Book Project, read the documentation.