DO CASE ... ENDCASE Command

Example   See Also

Executes the first set of commands whose conditional expression evaluates to true (.T.).

Syntax

DO CASE
  CASE lExpression1
     Commands
  [CASE lExpression2
     Commands
   ...
  CASE lExpressionN
     Commands]
  [OTHERWISE
     Commands]
ENDCASE

Arguments

CASE lExpression1 Commands ...

When the first true (.T.) CASE expression is encountered, the set of commands following it is executed. Execution of the set of commands continues until the next CASE or ENDCASE is reached. Execution then resumes with the first command following ENDCASE.

If a CASE expression is false (.F.), the set of commands following it up to the next CASE clause is ignored.

Only one set of commands is executed. These are the first commands whose CASE expression evaluates to true (.T.). Any succeeding true (.T.) CASE expressions are ignored.

OTHERWISE Commands

If all of the CASE expressions evaluate to false (.F.), OTHERWISE determines if an additional set of commands is executed.

Remarks

DO CASE is used to execute a set of Visual FoxPro commands based on the value of a logical expression. When DO CASE is executed, successive logical expressions are evaluated; the values of the expressions determine which set of commands is executed.

Comments can be placed after DO CASE and ENDCASE on the same line. The comments are ignored during program compilation and execution.