C ++ difference in the break, continue, return of

the end nearest break while, do while, for a switch statement, or (in a multilayer cycle, only one bounce outwardly);

continue is the end of a single cycle, and continue with the next cycle (only appears in for, while or do while loop, the end of the cycle being executed into the next cycle condition);

return the program returns, the following code will not execute (the end of the current method returns);

E.g:

while(x++ < 10)
{
    if(x == 3)
    {
        break;
    }
    printf("%d\r\n", x);
}

Result, the output 12 of the whole exit while loop;


Use continue

while(x++ < 10)
{
    if(x == 3)
    {
        continue;
    }
    printf("%d\r\n", x);
}


The result is: 1245678910 he simply not visible output 3, as he concluded this cycle ile (x ++ <10)
 

Guess you like

Origin blog.csdn.net/zfjBIT/article/details/93485066