2. The Case Construct
Used in cases where exactly one of several alternative actions is
selected and performed.
form
Select Case(Selector)
case(label-list1)
statement sequence1
case(label-list2)
statement sequence2
“
case(label-list n)
statement sequence n
End select
3.
Selector is an integer, character, or logical
expression.
The values in the list may have any of the forms:
(value)
single value
(value1: value2) range of values from value1 through
value2.
(value1:)
range of values greater than or equal
to value1
(: value2)
range of values less than or equal to
value2
5. Example: Pollution Index
A case statement can be used to carry
out the classification given (good, fair,
or poor).
A case statement can be used to
replace an IF / ELSE IF structure.
7. Range Selectors “Characters”
Select Case(char)
case(‘A’: ‘Z’)
Print*, ‘uppercase’
case(‘a’: ’z’)
Print*, ‘lowercase’
case(‘0’:’9’)
Print*, ‘numbers’
case default
Print*, ‘Not a letter or number’
End Select
8. What about real valued selectors??
A selector can’t be of type real.
To make a selection, convert the real
number to an integer and then use it
for the selection.
9. example
Suppose a motors’ RPM is determined by an indicator x.
high speed
x>= 5.5
normal speed 2.5<= x < 5.5
Low speed
x < 2.5
Select Case(int(10*x))
case(55:)
print*, ‚HIGH SPEED‛
case(25:54)
print*, ‚NORMAL SPEED‛
case(:24)
print*, ‚LOW SPEED‛
End Select