Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>if()/iif()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
IF()/IIF()


Syntax:     IF(<expL>, <exp1>, <exp2>)/IIF(<expL>, <exp1>, <exp2>)

Purpose:    To return the result of one of two specified expressions,
            depending upon the logical state of the given condition.

Arguments:  <expL> is a logical expression to be evaluated.

            <exp1> is the value to return if <expL> is true (.T.).

            <exp2> is the value to return if <expL> is false (.F.).

            Note that unlike other dialects, <exp1> and <exp2> can
            evaluate to different data types.  Note also that only the
            expression selected by the result of <expL> is evaluated.
            This means that an undefined or erroneous argument for the
            non-executed expression does not generate a runtime error.

Returns:    A value of any data type.

            IF() returns the evaluation of the argument pointed to by
            the result of the logical expression argument.  Since the
            two return arguments can be different data types, the value
            returned is the data type of the evaluated return argument.

Usage:      IF() 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 data type expression to another data type.  For
            example, the following converts a logical to a numeric:

            IF(<condition>, 0, 1)

            This leads to a number of applications.  You can, for
            example, format a logical field:

            IF(Paid, SPACE(10), "Go get'em")

            If you are printing forms, you may want to print an
            indicating symbol in different columns depending on the
            value of a logical field.  For example:

            @ <row>, IF(In_hosp, 10, 12) SAY "X"

            INDEXing is another area where IF() is useful.  You may want
            to create a key based on a logical field or add a key
            depending on a condition.  This latter might be the case if
            the key field is empty.  In this case, you want the contents
            of another field to be the key value.  For example:

            INDEX ON IF(EMPTY(Name), Company, Name);
               TO <ntx file>

            You can also use IF() to force the LABEL FORM to print blank
            lines.  For example:

            IF(EMPTY(<expC>), CHR(255), <expC>)

Library:    CLIPPER.LIB


----------------------------------- Examples -------------------------------

   a = 100
   ? IF(a > 50, "greater", "less")        && Result: greater
   a = 10
   ? IF(a > 50, "greater", "less")        && Result: less
   ? IF(a > 50, .T., 0)                   && Result: 0
   ? IF(.F., "Bad" + 12, "Good")          && Result: Good


See Also: DO CASE IF

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson