Break and Continue Statement in C

 



Break and continue

* Using to bring the program control out of the loop
* The break statement is used inside loops or switch statement.
* Break statement can used with
1. Loops
2. Switch case expression

int main(int argc, char const *argv[])
{
    printf("Hello world");
    int i;
    int age;
    for (i = 0; i < 10; i++)
    {
       printf("%d\nEnter your age\n",i);
       scanf("%d",&age);
       if (age>10)
       {
           break;
       }

    }
    return 0;
}

CONTINUE STATEMENT
* Used to bring the program control to next iteration of the loop
* The continue statement skips some code inside the loop and continue with the next iteratio.
* It is mainly used for a condition so that we can skip some lines of code for a particular condition.

#include <stdio.h>
int main(int argc, char const *argv[])
{
    int i, age;
    printf("Hello World\n");
    for (i = 0; i < 10; i++)
    {
        printf("%d\n Enter your age\n");
        scanf("%d", &age);
        if (age > 10)
        {
            continue;
        }
        printf("Himanshu is a good boy\n");
        printf("Monu is a good boy\n");
        printf("Sonu is a good boy \n");
        printf("Gonu is a good boy \n");
        printf("Khonu is a good boy \n");
    }
    return 0;
}