xHarbour Reference Documentation > Statement Reference |
Executes a block of statements based on one or more conditions.
DO CASE CASE <Condition1> <Statements1> [ CASE <ConditionN> <StatementsN> ] [ OTHERWISE <defaultStatements> ] END[CASE]
This statement executes a block of statements if the condition, related to the block, evaluates to true. If a condition evaluates to true, the following statements are executed until the next CASE, OTHERWISE or END[CASE] statement is encountered.
If no condition in the entire DO CASE structure evaluates to true, control is passed to the first statement following the ENDCASE statement.
It is possible to include other control structures like DO WHILE and FOR within a single DO CASE structure.
Note: The DO CASE...ENDCASE statement is equal to the IF...ELSEIF...ENDIF statement.
An alternative to DO CASE is the SWITCH statement which operates with constant values rather than logical conditions.
See also: | BEGIN SEQUENCE, DO WHILE, FOR, IF, SWITCH |
Category: | Control structures , Statements |
// This example shows the use of the DO CASE statement. PROCEDURE Main ACCEPT "Enter a number: " TO nNumber nNumber := Val(Alltrim(nNumber)) DO CASE CASE nNumber = 1 ? "the number was 1" CASE nNumber = 2 ? "the number was 2" OTHERWISE ? "the number was not 1 or 2" ENDCASE RETURN
http://www.xHarbour.com