C5_IF ( Statement )

IF
 Execute one of several alternative blocks of statements
------------------------------------------------------------------------------
 Syntax

     IF <lCondition1>
        <statements>...
     [ELSEIF <lCondition2>]
        <statements>...
     [ELSE]
        <statements>...
     END[IF]

 Arguments

     <lCondition> is a logical control expression.  If it evaluates to
     true (.T.), all following statements are executed until an ELSEIF, ELSE,
     or ENDIF is encountered.

     ELSEIF <lCondition> identifies statements to execute if the
     associated condition evaluates to true (.T.) and all preceding IF or
     ELSEIF conditions evaluate to false (.F.).  Any number of ELSEIF
     statements can be specified within the same IF...ENDIF control
     structure.

     ELSE identifies statements to execute if the IF and all preceding
     ELSEIF conditions evaluate to false (.F.).

 Description

     The IF control structure works by branching execution to statements
     following the first true (.T.) evaluation of the IF or any ELSEIF
     condition.  Execution then continues until the next ELSEIF, ELSE, or
     ENDIF is encountered whereupon execution branches to the first statement
     following the ENDIF.

     If no condition evaluates to true (.T.), control passes to the first
     statement following the ELSE statement.  If an ELSE statement is not
     specified, control branches to the first statement following the ENDIF
     statement.

     IF...ENDIF structures may be nested within IF...ENDIF structures and
     other control structure commands.  These structures, however, must be
     nested properly.

     The IF...ELSEIF...ENDIF form of the IF construct is identical to DO
     CASE...ENDCASE.  There is no specific advantage of one syntax over the
     other.  The IF construct is also similar to the IF() function which can
     be used within expressions.

 Examples

     .  This example evaluates a number of conditions using an
        IF...ELSEIF...ENDIF construct:

        LOCAL nNumber := 0
        //
        IF nNumber < 50
           ? "Less than 50"
        ELSEIF nNumber = 50
           ? "Is equal to 50"
        ELSE
           ? "Greater than 50"
        ENDIF

See Also: BEGIN SEQUENCE DO CASE DO WHILE FOR IF()



C5_IF ( Function )

 IF()
 Return the result of an expression based on a condition
------------------------------------------------------------------------------
 Syntax

     IF(<lCondition>, <expTrue>, <expFalse>) --> Value

 Arguments

     <lCondition> is a logical expression to be evaluated.

     <expTrue> is the value, a condition-expression, of any data type,
     returned if <lCondition> is true (.T.).

     <expFalse> is the value, of any date type, returned if <lCondition>
     is false (.F.).  This argument need not be the same data type as
     <expTrue>.

 Returns

     IF() returns the evaluation of <expTrue> if <lCondition> evaluates to
     true (.T.) and <expFalse> if it evaluates to false (.F.).  The value
     returned is the data type of the valid condition-expression.

 Description

     IF() is a logical conversion function.  It is one of the most powerful
     and versatile functions in Clipper.  It provides a mechanism to
     evaluate a condition within an expression.  With this ability you can
     convert a logical expression to another data type.

 Examples

     .  This example converts a logical data value to a numeric data
        value:

        lPaid = .T.
        ? IF(lPaid, 1, 0)               // Result: 1

     .  In this example a logical field is formatted depending on
        whether the Customer is past due or not:

        @ ROW() + 1, 25 SAY IF(lPaid, SPACE(10), "Go get 'em")

     .  If you are printing forms, you can print an indicating symbol
        in different columns depending on the value of a logical field:

        @ ROW(), IF(InHospital, 10, 12) SAY "X"

     .  You can also use IF() to force the LABEL FORM to print blank
        lines.  Enter the following expression when you create the label with
        RL.EXE:

        IF(EMPTY(Company), CHR(255), Company)

 Files   Library is CLIPPER.LIB.

Note : IF() is synonymous (shorthand)  of IIF().

See Also: DO CASE IF() IIF()



Using code blocks, again

Using code blocks again (.pdf)