case statement

The case statement delineates a conditional case construct.

Syntax

begin case
   case logical.exp 
   {statement{s}}
 .
   case logical.exp 
   {statement{s}}
 .
 .
end case

Description

Only the statements following the first true case statement are executed. Upon completion of these statements, program execution continues immediately following the end case statement.

If all case statements evaluate false, program execution is continued at the first statement after the end case.

A case 1 statement always evaluates true and is used as the last case statement to be processed only when all previous case statements evaluate to false.

The case statement is equivalent to nested if expressions as follows:

if logical.exp then
      {statement{s}}
   end else
      if logical.exp then
         {statement{s}}
   end
end

The statements between case statements are executed if the expression associated with the case statement evaluates to true. If the expression evaluates to false, the statements are not executed.

Example(s)

begin case
* check for operators response
case response = "p"
   printer on
case response = "s"
   echo off
case 1
   crt "response must be ’p’ or ’s’"
end case

In this example, if the response is p, the printer on statement is issued. The program would then branch to the next statement after end case. The case 1 is executed only if response is neither p nor s.