-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two simple examples on using 'switch case'
- Loading branch information
1 parent
678bfc3
commit 6aa71e4
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
|
||
int main(void) | ||
{ | ||
/* | ||
The structure of a switch can be more flexible than if-else. | ||
But for the `case` part, its value MUST be int constant expressions (e.g. 'a', 1). | ||
*/ | ||
switch ('o') | ||
{ | ||
case 'm': | ||
puts("m: Miss Fortune"); | ||
break; | ||
case 'i': | ||
puts("i: Irelia"); | ||
break; | ||
|
||
default: | ||
puts("Um.. what?"); | ||
break; | ||
} | ||
|
||
switch (3) | ||
{ | ||
default: | ||
puts("++++ ..... +++"); | ||
case 4: | ||
puts("++++"); | ||
case 3: | ||
puts("+++"); | ||
case 2: | ||
puts("++"); | ||
case 1: | ||
puts("+"); | ||
case 0:; | ||
} | ||
} |