50: ***(Syntax)*** Switch Statement
Switch Statement
Syntax:
switch (expression)
{
case /* constant-expression */:
/* code */
break;
default:
break;
}
Important points:
- You cannot add inequalities like percentage < 80 in the case of switch statement.
- You can use ranges in case like:
- '0' ... '9'
- 'a' ... 'z'
- 'A' ... 'Z'
- If there is same output for various cases, you cannot do:
- switch (alpha){case 'A' || 'a' || 'E' || 'r' || 'I' || 'i' || 'O' || 'o' || 'U' || 'u':cout << "This is a vowel";break;default:break;}
- If there is same output for various cases, you can do:
- switch (alpha){case 'A':case 'a':case 'E':case 'e':case 'I':case 'i':case 'O':case 'o':case 'U':case 'u':cout << "This is a vowel";break;default:break;}
Comments
Post a Comment