Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

The break statement

C Programming Language break statement

 

The statement that is used to break/stop the flow of loops & switch statement is known as break statement.

Inside the loop, break statement terminates the loop execution when it is encountered.

Inside switch statement, break statement is used to jump out of the switch statement instantly when it is encountered.

Syntax

break;

Working

C Programming Language break statement Working

After terminating a loop by using the break statement, program control is transferred immediately to the statement after the loop.

Example No 1

#include<stdio.h>
int main()
{
    int x;
    for(x=11;x<=20;x++)
    {
        if(x%5==0)
            break;
		
        printf("\n %d",x);
    }
    printf("\n Outside loop");
    return 0;
}

Output

 11
 12
 13
 14
 Outside loop

Example No 2

#include<stdio.h>
int main()
{
    int x;
    x=11;
    while(x<=20)
    {
        if(x%5==0)
            break;
		
        printf("\n %d",x);
        x++;
    }
    printf("\n Outside loop ");
    return 0;
}

Output

 11
 12
 13
 14
 Outside loop

 

Leave a reply