Write a program in C++ to explain the use of for loop, while loop, switch-case, break and continue statements.


Write a program in C++ to explain the use of for loop, while loop, switch-case, break and continue statements.

#include<iostream>
using namespace std;

int main()
{
    int choice,a;
    cout << "\nMenu\n";
    cout << "1. Example of For Loop \n";
    cout << "2. Example of While Loop \n";
    cout << "3. Example of break and continue \n";
    cout << "Enter choice";
    cin >> choice;
    switch(choice)
    {
       case 1:
       cout << "Repeating three times using for loop \n";
       for(int i=1;i<=3;i++)
          cout << "Printing...\n";
       break;
       case 2:
       cout << "Repeating three times using while loop \n";
       a = 1;
       while(a <= 3)
       {
          cout << "Printing again...\n";
          a++;
       }
       break;
       case 3:
       cout << "Example of break inside loop ";
       for(int i=1; i <= 10; i++)
       {
          if(i == 3)
          {
             cout << "\nusing break when i is 3";
             break;
          }
          cout << i << " ";
       }
       cout << "Example of coninue inside loop ";
       for(int i=1; i<=10; i++)
       {
          if( i == 3)
          {
             cout << "\nusing continue when i is 3";
             continue;
          }
          cout << i <<" ";
       }
    }
    return 0;
}