if, elif, else and endif directives

Inno Setup Preprocessor

if, elif, else and endif directives

Syntax

if-directive: if <expr>
elif-directive: elif <expr>
else-directive: else
endif-directive: endif

Description

The if directive, with the elif, else, and endif directives, controls compilation of portions of a source file. If the expression you write (after the if) has a nonzero value, the line group immediately following the if directive is retained in the translation unit.

Each if directive in a source file must be matched by a closing endif directive. Any number of elif directives can appear between the if and endif directives, but at most one else directive is allowed. The else directive, if present, must be the last directive before endif.

The if, elif, else, and endif directives can nest in the text portions of other if directives. Each nested else, elif, or endif directive belongs to the closest preceding if directive.

All conditional-compilation directives, such as if and ifdef, must be matched with closing endif directives prior to the end of file; otherwise, an error message is generated. When conditional-compilation directives are contained in include files, they must satisfy the same conditions: There must be no unmatched conditional-compilation directives at the end of the include file.

The preprocessor selects one of the given occurrences of text for further processing. A block specified in text can be any sequence of text. It can occupy more than one line. Usually text is program text that has meaning to the compiler or the preprocessor.

The preprocessor processes the selected text and passes it to the compiler. If text contains preprocessor directives, the preprocessor carries out those directives. Only text blocks selected by the preprocessor are compiled.

The preprocessor selects a single text item by evaluating the expression following each if or elif directive until it finds a true (nonzero) constant expression. It selects all text (including other preprocessor directives) up to its associated elif, else, or endif.

If all occurrences of constant-expression are false, or if no elif directives appear, the preprocessor selects the text block after the else clause. If the else clause is omitted and all instances of constant-expression in the if block are false, no text block is selected.

Inline conditional directives must not be mixed with simple. If the if directive is simple (it occupies one line), its associated directives (elif, else, or endif) must also be simple, as opposed to inline (the directives that are embedded in text lines).

Examples

#define Lang

[Tasks]
#if "English" == Lang = ReadIni(SetupSetting("MessagesFile"), \
  "LangOptions", "LanguageName")
  Description: "For all users"; Name: all
#elif "German" == Lang
  Description: "Fur alle"; Name: all
#else
# error Unsupported language
#endif