Professional Documents
Culture Documents
CONTROL STRUCTURES 1
(SELECTION)
1
Selection: if and if...else
2
One-Way Selection
4
Two-Way Selection
6
Compound (Block of) Statements
8
Multiple Selections: Nested if
9
Multiple Selections: Nested if
(cont’d.)
11
Comparing if…else Statements
with if Statements (cont’d.)
12
Conditional Operator (?:)
13
switch Structures
• Expression is sometimes
called the selector
14
switch Structures (cont’d.)
15
switch Structures (cont’d.)
• One or more statements may follow a case
label
• Braces are not needed to turn multiple
statements into a single compound
statement
• When a case value is matched, all
statements after it execute until a break is
encountered
• The break statement may or may not
appear after each statement
• switch, case, break, and default are
16
reserved words
switch Structures (cont’d.)
17
Programs
18
Programs
19
Programs
21
Programs