Contents - Index


CASE

 

CASE statements provide logical operations and they are similar to IF-THEN-ELSE statements in this respect.  Like IF-THEN-ELSE and REPEAT-UNTIL statements, CASE statements can only be used in EES Functions or Procedures.  CASE statements somewhat more convenient to use when the logic control must select from multiple options.

 

The CASE statement must be followed on the same line with the CASE decision variable, which may be an EES numerical (e.g., X) or string variable (e.g., X$).  The CASE options are identified with CASE labels followed by a double colon (::).  If the CASE decision variable is an EES numerical variable, the CASE labels must be integers.  If the CASE decision variable is a string variable, the Case labels must be string constants surrounded by single quotes.  An equation is normally placed on the same line after the CASE label.  Additional equations may follow and these equations will be executed if the Case variable matches the CASE label.  An ELSE label may optionally be used (without quotes) with either the numerical or string versions.  Control will transfer to the first equation after the ELSE keyword if the CASE variable does not match any of the CASE labels.  An ENDCASE keyword is used to finalize the CASE statement.

 

CASE statements may not be used in a nested manner.  Simple examples of the CASE statement follow to illustrate the syntax.

 

 

FUNCTION TESTCASE(V)

   CASE V

      1:: X=V+41

           Y=SQRT(X)

           TESTCASE=X+Y

      3:: TESTCASE=V^2

      5:: GOTO 3

   else:: Call Error('The CASE value must be 1, 3, or 5.  A value of XXXF0 was provided.',V)

   ENDCASE

   Return

   3:  TESTCASE=3

END

G=TESTCASE(1)

 

 

PROCEDURE MDAS(OP$,X,Y: R)

   Case OP$

        'Multiply'::  R=X*Y

        'Divide'::     If (Y<>0) Then 

                            R=X/Y

                          Else

                            Call Error('Attempt to divide by zero.')

                          Endif

        'Add'::         R=X+Y

        'Subtract'::  R=X-Y

        ELSE::       R=0

   Endcase

End     

 

Call Mdas('Divide',3,4:R)

 

See Also:

    IF-THEN-ELSE 

    REPEAT-UNTIL

    EES Functions 

    EES Procedures