[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
+---------------------------------+
|          IF ... ENDIF           |
+---------------------------------+
IF <expL>
                <statements1>
        [ELSE
                <statements2>]
ENDIF

-----------------------------------
Processes commands based on a condition.
-----------------------------------

In this structured programming command, <expL> is evaluated.  If <expL>
is true, then any statements following the IF and prior to either a
matching ELSE or ENDIF (whichever occurs first) will be executed.

If <expL> is false and ELSE has been included, then any statements after
the ELSE and before the ENDIF are executed.

If <expL> is false and an ELSE has not been included then all statements
between the IF and the ENDIF are ignored.  In this case, the program
will continue with the first statement following ENDIF.

IFs may be nested within one another provided that each IF has a
matching ENDIF.

Comments may be placed on the same line after IF, ELSE and ENDIF.  These
comments are ignored during program execution.

Clauses
-------

<expL>
        If <expL> is .T., <statements1> is processed.  Otherwise, <statements2>
is processed.

+---------------------------------+
|         Program Example         |
+---------------------------------+
IF USED('customer')
        SELECT customer
ELSE
        USE LOCFILE('customer.dbf','DBF','Where is CUSTOMER.DBF?')
ENDIF
GETEXPR 'Enter condition to locate ' TO temp;
        TYPE 'L' DEFAULT 'COMPANY = ""'
LOCATE FOR &temp && Enter LOCATE expression
IF FOUND()      && Was it found?
        ? 'Company: ' + company  && If so display a message
ELSE                       && If not found
        ? 'Condition ' + temp + ' was not found ' && Display a message
ENDIF
USE

-----------------------------------

See Also:  DO CASE, DO WHILE, FOR ... ENDFOR, IIF(), SCAN

-----------------------------------

See Also: DO CASE DO WHILE FOR ... ENDFOR IIF() SCAN
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson