Break and continue

Break Keyword:

The break keyword is used to break the flow of iteration and come out from the loop.


It is also used in switch...case to come out from the scope if the particular case is matched. Here if we do not write a break statement in the switch...case then the flow will continue to execute until the next break statement is encountered or until the scope ends.


Syntax:

break;

Example:

for(i=i; i<=5; i++)

{

    if(i==3)

        break;

    printf("%d, ", i);

}


Continue Keyword:

The continue keyword is used to skip the iteration only once and continue afterward.


Syntax:

continue;

Example:

for(i=i; i<=5; i++)

{

    if(i==3)

        continue;

    printf("%d, ", i);

}

Comments

Popular posts from this blog

C program to read and display book information using structure

Count positive, negative and zero values in an array

Maximum value from array