Break and continue


Break  and continue 

The break statement is used to exit from a while, do-while, for, or switch structure. It can only be used inside the body of a for, while, do-while, or in switch statements. The break statement is written simply as a break; without any embed. 

Continue to skip the remaining states in the body of for, while, or do-while structure. It proceeds with the next iteration of the loop. It can be used in a while loop, do-while loop, and for a loop.  

 

Syntax  

if(condition) 

{ 

    Continue; 

}  

If( condition) 

{ 

    Break; 

} 

 

printf(statement); 

 

 

Structure  

 

 

 

Program 

QUESTION: write a c program using break and continue statement.  

#include <stdio.h>

#include <conio.h>

int main()

{

    int no;

    printf("enter a value of no: ");

    scanf("%d", &no);

    for (int i = 1i <= noi++)

    {

        if (i == 3)

        {

            continue// loop will reverse from here but value won't be display on the screen.
        }

        if (i == 10)

        {

            break// exit the condition
        }

        printf("%d  "i);
    }

    return 0;

    getch();
}


OUTPUT

enter a value of no: 7

1  2  4  5  6  7  


Follow our page for regular updates.

0 Comments