SWITCH Examples


Example 1:

 

DOW

FORM

1

DVAR1

INIT

"A"

.

 

 

  

CLOCK

WEEKDAY,DOW

.

 

 

  

DISPLAY

"The current day of the week is ";

.

 

 

  

SWITCH

DOW

  

CASE

"1"

  

DISPLAY

"Sunday";

  

CASE

"2"

  

DISPLAY

"Monday";

  

CASE

"3"

  

DISPLAY

"Tuesday";

  

CASE

"4"

  

DISPLAY

"Wednesday";

  

CASE

"5"

  

DISPLAY

"Thursday";

  

CASE

"6"

  

DISPLAY

"Friday";

  

CASE

"7"

  

DISPLAY

"Saturday";

  

DEFAULT

 

  

DISPLAY

"Invalid";

  

ENDSWITCH

 

.

 

 

  

DISPLAY

"."

 

This example retrieves the current day of the week and uses the SWITCH statement to display its name.

Example 2:

 

V

FORM

2

.

 

 

  

SWITCH

V

  

CASE

"1" OR "2" OR "3"

  

DISPLAY

*HD,"Switch V=1 OR 2 OR 3:V = ",V

  

CASE

"4"

  

DISPLAY

*HD,"Switch V=4:V = ",V

  

CASE

"5"

  

DISPLAY

*HD,"Switch V=5:V = ",V

  

CASE

"6"

  

DISPLAY

*HD,"Switch V=6:V = ",V

  

ENDSWITCH

 

 

This example shows the use of multiple case selection criteria in a CASE statement.

 



PL/B Language Reference SUBTRACT Examples TAN Example