Article Directory
-
Chapter 49 Caché Command Encyclopedia IF (Old Version) Command - Outline
- description
- IF without parameters
- With parameters
Chapter 49 Caché Command Encyclopedia IF (Old Version) Command
Calculate an expression, and then select the line of code to be executed based on the truth value of the expression.
Outline
IF expression command1
ELSE command2
I expression command1
E command2
parameter
- expression Optional-an expression (or a comma-separated list of expressions) that evaluates to a Boolean value.
- command1 If the calculation result of expression is TRUE, or expression is omitted, execute one or more Caché commands.
- ELSE command2 If the calculation result of the expression is FALSE, execute one or more Caché commands. The ELSE keyword is optional.
description
Note: This page describes the IF
old version of the command. This version is considered an old version starting from Caché 4.0 and should not be used in new programming. It is described here only for compatibility with older applications.
Traditional IF
commands are line-oriented. The command to be executed must follow it in the same program line. No curly braces are used, and the line format is restrictive. The new IF
command is block-structured; the block it executes consists of the IF
commands found in curly braces after the command. There are no restrictions on the line format (spaces, newlines). IF
The new version of does not use $TEST
special variables.
IF
And ELSE
the old and new forms syntactically different, should not be used in combination; therefore, should ELSE IF one type with another type of pairing.
IF
There are two forms of commands:
- With parameters
- No parameters
IF without parameters
If $TEST
the current value of the variable is TRUE (non-zero), the IF
command without expression parameters will be executed on the same line. If it $TEST
is FALSE (0), Caché will ignore the remaining commands on that line and continue to execute the next line (usually a ELSE
command). Therefore, the ELSE
keyword is equivalent to IF'$TEST
(if $TEST
FALSE).
With parameters
If the calculation result of expression is TRUE (non-zero), the IF with the expression parameter will execute the command on the same line. (Caché will also be $TEST
set to TRUE.) If the calculation result of expression is FALSE, Caché will be $TEST
set to FALSE (0), ignore the rest of the commands on the line, and continue to execute the next line.
The next line usually starts with a ELSE
keyword, and then one or more commands follow on the same line. IF
The command does not require ELSE
keywords, but needs ELSE
to specify IF
options that are executed only when it is false. Always specify ELSE
is the recommended programming practice.
This line-oriented ELSE
keyword can be abbreviated as E
. (Not a block-oriented abbreviated new ELSE
keywords.) IF
And ELSE
the old and new forms syntactically different, should not be used in combination; therefore, one type IF
should not be another type of ELSE
pairing.
The expression parameter can take the form of a single expression or a comma-separated list of expressions. For expression lists, Caché evaluates each expression in order from left to right. If it encounters a FALSE expression, it will stop evaluating. If the result of all expressions is TRUE, Caché executes the command after the expression parameter in that line. If any expression evaluates to FALSE, Caché ignores all remaining expressions and does not execute the command in that line, but continues to execute in the next line of code.