-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_flow_control.c
More file actions
38 lines (34 loc) · 872 Bytes
/
04_flow_control.c
File metadata and controls
38 lines (34 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdbool.h> // Required to use booleans
int main() {
puts( "Conditionals:" );
puts( "if, else and switch" );
if( false ) {
puts( "Entered if!" );
} else if( 5 == 'd' ) {
puts( "Entered else if!" );
} else {
puts( "Entered else!" );
}
/*
* Switch can only evaluate char and int values
*/
switch( 'd' ) {
case 1:
case 2:
case 3:
puts( "Number between 1 and 3!" );
break;
case 'a':
case 'b':
case 'c':
puts( "Letter between a and c!" );
break;
case 'd':
puts( "It's a d!" );
default:
puts( "Default case enter beacuse case 'd' didn't have a break sentence" );
break; // break isn't required but can be added
}
return 0;
}