Evaluates an expression, then selects which line of code to execute based on the truth value of the expression.
IF expression command1 ELSE command2 I expression command1 E command2
|One or more Caché commands that are executed if
||One or more Caché commands that are executed if
This page describes the legacy version of the
IF command. This version is considered legacy as of Caché 4.0, and should not be used in new programming. It is described here solely for compatibility with legacy applications.
IF command is line-oriented; commands to be executed must follow it on the same program line. Curly braces are not used and line formatting is restrictive. The new IF command is block structured; the block it executes consists of commands found within the curly braces that follow the IF command. Line formatting (white space, line breaks) is unrestrictive. The new version of IF does not use the $TEST special variable.
IF command has two forms:
Without an argument
With an argument
IF Without an Argument
IF With an Argument
The next line typically begins with an
ELSE keyword, followed by one or more commands on the same line. The IF command does not require an ELSE keyword, but ELSE is required to specify an option that is only executed when IF is false. Always specifying ELSE is a recommended programming practice.
ELSE keyword can be abbreviated as E. (The newer block-oriented ELSE keyword cannot be abbreviated.) The old and new forms of IF and ELSE are syntactically different and should not be combined; therefore, an IF of one type should not be paired with an ELSE of the other type.
expression argument can take the form of a single expression or a comma-separated list of expressions. For an expression list, Caché evaluates the individual expressions in left to right order. It stops evaluation if it encounters an expression that is FALSE. If all expressions evaluate to TRUE, Caché executes the command(s) following the expression argument on that line. If any expression evaluates to FALSE, Caché ignores any remaining expressions, and does not execute the commands on that line, but continues execution at the next line of code.