break Statement 

The break statement ends the loop immediately when it is encountered.

The syntax of break Statement:

break;


The break statement is almost always used with if...else statement inside the loop.


Example :

#include <stdio.h>

void main()

{


    int no;


    for(no=1;no<10;n++)

    {

        if(no==5)

        {

            break;

        }

    printf("%d",no);

}


}


Output: 1 2 3 4


In above program when no = 5 break statement is executed and program control is outside of loop


continue Statement :


The continue statement skips the current iteration of the loop and continues with the next iteration.


The syntax of continue Statement:


continue;



The continue statement is almost always used with if...else statement inside the loop.


Example :

#include <stdio.h>

void main()

{

    int no;


    for(no=1;no<=10;n++)

    {

        if(no==5)

        {

            continue;

        }

        printf(" %d ",no);

    }

}


Output: 1 2 3 4 6 7 8 9 10


In above program when no = 5, continue statement is executed and that iteration is skipped.

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post