# !if(4)

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

## NAME

!if, !elif, !else, !endif - Conditional statements

## SYNOPSIS

!if condition

... condition body ...

[!elif condition

... condition body ...

]
[!else

... condition body ...

]
!endif

## DESCRIPTION

The conditional directives allow statements to be executed only if a condition specified in the directive is met, as follows:-

- Every line following the !if directive, until the first !elif, !else or !endif directive, is only executed if the expression following the !if directive evaluates to a `TRUE` value (non-zero).

- If the !if evaluates to `FALSE` and a !elif directive is next then the expression following the !if is evaluated and following statements are executed if `TRUE`.

- If no !if or !elif is found to be `TRUE` and a !else is found then the statements following it are executed.

The condition may be any logical condition as evaluated by the variable functions (e.g. &equal(4)) returning `TRUE` or `FALSE`. An integer value, non-zero evaluates `TRUE`, zero evaluates to `FALSE`. A non-numerical argument, such as a string is always `FALSE`.

The conditional body may be any MicroEmacs 2009 function, macro or directive with the exception of define-macro and !emacro. All directives that alter the execution of the macro are handled correctly within the !if statement (e.g. !goto, !return etc.

## EXAMPLE

The following macro segment creates the portion of a text file automatically. (yes believe me, this will be easier to understand then that last explanation....)

    !if &sequal %curplace "timespace vortex"
        insert-string "First, rematerialize\n"
    !endif
    !if &sequal %planet "earth"	;If we have landed on earth...
        !if &sequal %time "late 20th century"  ;and we are then
            ml-write "Contact U.N.I.T."
        !elif &sequal %time "pre 20th century"
            ml-write "start praying for a miracle"
        !else
            insert-string "Investigate the situation....\n"
            insert-string "(SAY 'stay here Sara')\n"
        !endif
    !else
        set-variable %conditions @ml"Atmosphere conditions outside? "
        !if &sequal %conditions "safe"
            insert-string &cat "Go outside......" "\n"
            insert-string "lock the door\n"
        !else
            insert-string "Dematerialize..try somewhere else"
            newline
        !endif
    !endif

## SEE ALSO

Variable Fuctions, !goto(4), &equal(4), !return(4), $status(5).

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

</HMTL>