Example program break continue goto statement in C C++

Example programs for break, continue and goto statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

break statement example program in C

#include<stdio.h>
int main()
{
    int n=1;
    while (n<=3)
    {
        printf("ABC\n");
        n++;
        break;
        printf("DEF\n");
    }
    return 0;
}

Output:

ABC

continue statement example program in C

#include<stdio.h>
int main()
{
    int n=1;
    while (n<=3)
    {
        printf("ABC\n");
        n++;
        continue;
        printf("DEF\n");
    }
    return 0;
}

Output:

ABC
ABC
ABC

goto statement example program in C

#include<stdio.h>
int main()
{
    int n=1;
    printf("ABC\n");
    goto xyz;
    printf("DEF\n");
    xyz:
    return 0;
}

Output:

ABC

Example programs for break, continue and goto statements in C++

break statement example program in C++

#include<iostream>
using namespace std;
int main()
{
    int n=1;
    while (n<=3)
    {
        cout<<"ABC\n";
        n++;
        break;
        cout<<"DEF\n";
    }
    return 0;
}

Output:

ABC

continue statement example program in C++

#include<iostream>
using namespace std;
int main()
{
    int n=1;
    while (n<=3)
    {
        cout<<"ABC\n";
        n++;
        continue;
        cout<<"DEF\n";
    }
    return 0;
}

Output:

ABC
ABC
ABC

goto statement example program in C++

#include<iostream>
using namespace std;
int main()
{
    int n=1;
    cout<<"ABC\n";
    goto xyz;
    cout<<"DEF\n";
    xyz:
    return 0;
}

Output:

ABC

Similar programs in C and C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Switch between Mon to Sun (switch case single case)
  10. Checking vowel or consonant (switch case multiple case)
  11. Number of days in a month (switch case multiple case)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer