Switch statement:
switch (expression)
{
case constant Expression 1: statement 1
Case constant Expression 2: statement 2
。。。
case constant Expression N: statement n
Default: Statement n+1
}
Description
(1) The expression in parentheses behind the switch, whose value enables shaping, character-type, enumerated data
(2) After executing a case branch, the process jumps out of the switch and is implemented with a break.
(3) The last branch (default) can be without break
(4) Multiple case can be shared with a group of execution statements
Example: Input score judgment level
#include <stdio.h>
int main (void)
{
int score;
scanf ("%d", &score);
if (score>100| | SCORE<0)
{
printf ("Input data is incorrect. \ n");
return 0;
}
Switch (SCORE/10)
{
Case 10:
Case 9:
Case 8:
printf ("excellent. \ n");
Break
Case 7:
printf ("good. \ n");
Break
Case 6:
printf ("Pass. \ n");
Break
Default
printf ("fail. \ n");
}
return 0;
}