C++ Program to illustrate use of switch case without break [DEVCPP/GCC]

SWITCH

A switch statement allows an integer variable to be tested for equality against a list of values. These values are provided through cases. The basic syntax of switch is given below:
switch(expression)
{
   case constant-expression  :
      statement(s);
      break;      //Optional
  
   case constant-expression  :
      statement(s);
      break;      //Optional
  
   default :      //Optional
      statement(s);
}
PROGRAM

// Program to illustrate use of switch case without break

#include <iostream>

using namespace std;

int main()
{
switch(2017)
{
case 2017:
{
cout<<"\nMay you get: \n";
}
case 1:
{
cout<<"\n\tHappiness";
}
case 2:
{
cout<<"\n\tJoy";
}
case 3:
{
cout<<"\n\tProsperity";
}
case 4:
{
cout<<"\n\tLove";
}
case 5:
{
cout<<"\n\tCare";
}
case 6:
{
cout<<"\n\tMoney";
}
case 7:
{
cout<<"\n\tSupport";
}
case 8:
{
cout<<"\n\tRespect";
}
case 9:
{
cout<<"\n\tBlessings";
}
case 10:
{
cout<<"\n\tHealth";
}
case 11:
{
cout<<"\n\tMotivation";
}
case 12:
{
cout<<"\n\tGuidance";
}
default:
cout<<"\n\nThis year!";
cout<<"\n\nHappy New Year Guys!";
}
}

OUTPUT

C++ Program to illustrate use of switch case without break

Share this

Related Posts

FIND US ON FACEBOOK!