MEX04-14 example program illustrating the use of SELECT CASE statements:

 

! MExample Program 4-14

! Display the result of reading a thermometer.

! Include new cases.

! Try for Temperatures 91, 94, 97.5, 98.6, 99, 105, 110

! do trace, slow (Temperature)

 

DO while more data

READ Temperature

PRINT Temperature;

!INPUT prompt "Reading? ": Temperature !remove ! for user input ! DO READ LOOP

SELECT CASE Temperature

CASE is < 93 ! new case

PRINT "You may have a thyroid condition."

CASE 93 to 97 ! new case

PRINT "Temperature is quite subnormal."

CASE 97 to 98.5

PRINT "Temperature is subnormal."

CASE 98.5 to 98.7

PRINT "Normal temperature."

CASE is > 105 ! new case

PRINT "Get to a hospital immediately!"

CASE 98.7 to 105

PRINT "You have a fever."

END SELECT

LOOP

DATA 91, 94, 97.5, 98.6, 99, 105, 110

END

This gives the output:

91 You may have a thyroid condition.

94 Temperature is quite subnormal.

97.5 Temperature is subnormal.

98.6 Normal temperature.

99 You have a fever.

105 You have a fever.

110 Get to a hospital immediately!