xHarbour Reference Documentation > Statement Reference |
Executes a block of statements based on one or more conditions.
IF <Condition1> <Statements> [ ELSEIF <ConditionN> <Statements> ] [ ELSE <Statements> ] END[IF]
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 ELSEIF, ELSE or END[IF] statement is encountered.
If no condition in the entire IF...ELSEIF structure evaluates to true, control is passed to the first statement following the ELSE statement.
It is possible to include other control structures like DO WHILE and FOR within a single IF...ELSE structure.
Note: The IF...ELSEIF...ENDIF statement is equal to the DO CASE...ENDCASE statement.
See also: | BEGIN SEQUENCE, DO CASE, DO WHILE, FOR, If() | IIf(), SWITCH |
Category: | Control structures , Statements |
// The example shows different forms of the IF END[IF] statement. PROCEDURE Main LOCAL nSalary := 1600 IF .F. ? "This will never be executed" END IF .T. ? "This will always be executed" ENDIF IF nSalary < 1000 ? "Start looking for another job!" ELSEIF nSalary < 1500 ? "That's pretty good" ELSEIF nSalary < 2000 ? "You should be happy" ELSE ? "You should be very happy" ENDIF RETURN
http://www.xHarbour.com