Break and Continue Statement in C


The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.

Break :
   By using break,you can force immediate termination of a loop, bypassing the conditional expression and any remaininh code in the body of the loop.When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.

Continue :
   The continue statement performs such an action. In for, while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop.

Source Code

//Break & Continue
#include<stdio.h>
int main()
{
    int i,n,num,sum=0;
    printf("\nEnter The Limit : ");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        printf("\nEnter The Number : ");
        scanf("%d",&num); //1 2 3 0 5
        if(num==0)
            continue;
       sum+=num;
    }
    printf("\nTotal : %d",sum);
    return 0;
}
 

Output

Enter The Limit : 5

Enter The Number : 11

Enter The Number : 12

Enter The Number : 13

Enter The Number : 14

Enter The Number : 15

Total : 65
To download raw file Click Here

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C