C - Language Theory
Switch Statement
The control statement which allows us to make a decision from the number of choices is called a switch, or more correctly a switch-case-default, since these three keywords go together to make up the control statement.
Switch Statement
Each value is called a case, and the variable being switched on is checked for each switch case.
Syntax of Switch |
---|
switch(x) { Case 1: //code to be executed if x=1; break; Case 2: //code to be executed if x=2; break; Case n: //code to be executed if x=n; break; default: //code to be executed if x doesn't match any case; break; } |