# &cond(4)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

&cond - Conditional expression operator

## SYNOPSIS

&cond log expr1 expr2

## DESCRIPTION

The conditional expression &cond provides an alternative way to write !if-!else-!endif constructs, e.g.:-

    !if &gre %a %b
        set-variable %z %a
    !else
        set-variable %z %b
    !endif

may be replaced with a conditional expression, breaking down the components then

log is &gre %a %b
expr1 is %a
expr2 is %b

rewriting the expression we get:

    set-variable %z &cond &gre %a %b %a %b

This is far more concise, albeit a little less readable, but does improve the performance of macros as there is less information to interpret.

The &cond operator accepts three fields, ALL fields are evaluated although only one of the results expr1 or expr2 is used. The log field is a logical value, if it is non-zero (`TRUE`) then the result of the expr1 evaluation is used, otherwise the result of expr2 is used.

It should be noted that the conditional expression may be used in any construct i.e. &add(4), &cat(4), etc. the expr arguments may be strings, numbers or booleans the resultant value of the expr arguments is simply returned to the calling expression.

## SEE ALSO

Variable Functions, &add(4), &great(4).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>