Chapter 49 Caché Command Encyclopedia IF (Old Version) Command

Article Directory

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 IFold 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 IFcommands 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 IFcommand is block-structured; the block it executes consists of the IFcommands found in curly braces after the command. There are no restrictions on the line format (spaces, newlines). IFThe new version of does not use $TESTspecial variables.

IFAnd ELSEthe old and new forms syntactically different, should not be used in combination; therefore, should ELSE IF one type with another type of pairing.

IFThere are two forms of commands:

  • With parameters
  • No parameters

IF without parameters

If $TESTthe current value of the variable is TRUE (non-zero), the IFcommand without expression parameters will be executed on the same line. If it $TESTis FALSE (0), Caché will ignore the remaining commands on that line and continue to execute the next line (usually a ELSEcommand). Therefore, the ELSEkeyword is equivalent to IF'$TEST(if $TESTFALSE).

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 $TESTset to TRUE.) If the calculation result of expression is FALSE, Caché will be $TESTset 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 ELSEkeyword, and then one or more commands follow on the same line. IFThe command does not require ELSEkeywords, but needs ELSEto specify IFoptions that are executed only when it is false. Always specify ELSEis the recommended programming practice.

This line-oriented ELSEkeyword can be abbreviated as E. (Not a block-oriented abbreviated new ELSEkeywords.) IFAnd ELSEthe old and new forms syntactically different, should not be used in combination; therefore, one type IFshould not be another type of ELSEpairing.

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.

Guess you like

Origin blog.csdn.net/yaoxin521123/article/details/108069675