Switch Control Structure: Lecture #13
Switch Control Structure: Lecture #13
Switch Control Structure: Lecture #13
Lecture #13
switch Control Structure
case '3':
case '4':
actions /* one or more statements */
break;
default:
actions /* one or more statements */
break;
}
switch Structure
Useful when variable or expression is tested for multiple values
Consists of a series of case labels and an optional default case
true
case a case a action(s) break
false
true
case b case b action(s) break
false
.
.
.
true
case z case z action(s) break
false
default action(s)
1. Initialize variables
2. Input data
3. Print results
Program Output
Enter the letter grades.
Enter the EOF character to end input.
a
B
c
C
A
d
f
C
E
Incorrect letter grade entered. Enter a new grade.
D
A
b