Statement DO CASE Foundation

Executes one of several program sections

Syntax
 DO CASE
 CASE <lExpression1>
    <SourceCode>...
[CASE <lExpression2>]
    <SourceCode>...
[OTHERWISE]
    <SourceCode>...
 END[CASE]
Parameters
<lExpression>
<lExpression> is a logical expression. If its value is .T. (true), the code immediately following the CASE statement is executed, up to the following CASE, OTHERWISE or ENDCASE statement.
OTHERWISE
The OTHERWISE statement specifies a program section which is executed if none of the CASE conditions evaluates to .T. (true).
Description

DO CASE...ENDCASE is a control structure for branching program execution to code following the first CASE statement whose condition <lExpression> evaluates to .T. (true). The program lines which follow the CASE statement are executed up to the next CASE, OTHERWISE or ENDCASE statement. The program continues at the first executable program line following the ENDCASE statement. If all CASE conditions evaluate to .F. (false), execution continues following the OTHERWISE statement. If OTHERWISE is not specified, the program continues following the ENDCASE statement.

The number of CASE conditions for DO CASE is unlimited, and DO CASE can be nested to any depth. The control structure performs similar to the IF...ELSEIF...ELSE...ENDIF structure.

Examples
DO CASE usage
// The example shows a menu with three choices. 
// It shows a typical use of DO CASE. 

PROCEDURE Main 
   LOCAL nMenuItem 

   @ 2, 1 PROMPT " DBF file " 
   @ 4, 1 PROMPT " NTX file " 
   @ 6, 1 PROMPT " Search " 

   MENU TO nMenuItem 
   SetPos( 0, 0 ) 

   DO CASE 
   CASE nMenuItem == 1 
      ? "selects DBF file" 
   CASE nMenuItem == 2 
      ? "selects index file" 
   CASE nMenuItem == 3 
      ? "searches data record" 
   OTHERWISE 

      nMenuItem := Alert( "Exit program?", ; 
                          {" Yes "," No " }  ) 
      SetPos( 0, 0 ) 

      DO CASE 
      CASE nMenuItem == 0 
         ? "No selection met" 
      CASE nMenuItem == 1 
           QUIT 
      CASE nMenuItem == 2 
         ? "continues program" 
      ENDCASE 

   ENDCASE 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.