Skip to content

Commit

Permalink
Two simple examples on using 'switch case'
Browse files Browse the repository at this point in the history
  • Loading branch information
codingEzio committed Feb 14, 2020
1 parent 678bfc3 commit 6aa71e4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions level1_acquaintance/list1.5.c
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:;
}
}

0 comments on commit 6aa71e4

Please sign in to comment.