Switch Statement
#include <stdafx.h>
#include <iostream>
using namespace std;
/* Switch is a multiway decision statement in which we have a variable against a list of case values,and when a match is found, a block of statements
associated with that case is executed. */
int main()
{
int a = 2;
switch (a) { /* Here 'a' is the variable and 1,2,3 are the case values. */
case 1:
cout<< "Value of a is 1";
break;
case 2:
cout<< "Value of a is 2";
break;
case 3:
cout<< "Value of a is 3";
break;
}
return 0;
}
Output:
Value of a is 2