Skip to main content

Command Postconditional Expressions

Command Postconditional Expressions

When you specify an ObjectScript command, you can append to it a postconditional.

A postconditional is an optional expression that is appended to a command or (in some cases) a command argument that controls whether Caché executes that command or command argument. If the postconditional expression evaluates to TRUE (defined as nonzero), Caché executes the command or the command argument. If the postconditional expression evaluates to FALSE (defined as zero), Caché does not execute the command or command argument, and execution continues with the next command or command argument.

All ObjectScript commands can take a postconditional expression, except the flow-of-control commands (IF, ELSEIF, and ELSE; FOR, WHILE, and DO WHILE) and the block structure error handling commands (TRY, THROW, CATCH).

The ObjectScript commands DO and XECUTE can append postconditional expressions both to the command keyword and to their command arguments. A postconditional expression is always optional; for example, some of the command’s arguments may have an appended postconditional while its other arguments do not.

If both a command keyword and one or more of that command’s arguments specify a postconditionals, the keyword postconditional is evaluated first. Only if this keyword postconditional evaluates to TRUE are the command argument postconditionals evaluated. If a command keyword postconditional evaluates to FALSE, the command is not executed and program execution continues with the next command. If a command argument postconditional evaluates to FALSE, the argument is not executed and execution of the command continues with the next argument in left-to-right sequence.

Postconditional Syntax

To add a postconditional to a command, place a colon (:) and an expression immediately after the command keyword, so that the syntax for a command with a postconditional expression is:

Command:pc

where Command is the command keyword, the colon is a required literal character, and pc can be any valid expression.

A command postconditional must follow these syntax rules:

  • No spaces, tabs, line breaks, or comments are permitted between a command keyword and its postconditional, or between a command argument and its postconditional. No spaces are permitted before or after the colon character.

  • No spaces, tabs, line breaks, or comments are permitted within a postconditional expression, unless either an entire postconditional expression is enclosed in parentheses or the postconditional expression has an argument list enclosed in parentheses. Spaces, tabs, line breaks, and comments are permitted within parentheses.

  • Spacing requirements following a postconditional expression are the same as those following a command keyword: there must be exactly one space between the last character of the keyword postconditional expression and the first character of the first argument; for argumentless commands, there must be two or more spaces between the last character of the postconditional expression and the next command on the same line, unless the postconditional is immediately followed by a close curly brace. (If parentheses are used, the closing parenthesis is treated as the last character of the postconditional expression.)

Note that a postconditional expression is not technically a command argument (though in the ObjectScript reference pages the explanation of the postconditional is presented as part of the Arguments section). A postconditional is always optional.

Evaluation of Postconditionals

Caché evaluates a postconditional expression as either True or False. Most commonly these are represented by 1 and 0, which are the recommended values. However, Caché performs postconditional evaluation on any value, evaluating it as False if it evaluates to 0 (zero), and True if it evaluates to a nonzero value.

  • Caché evaluates as True any valid nonzero numeric value. It uses the same criteria for valid numeric values as the arithmetic operators. Thus, the following all evaluate to True: 1, “1”, 007, 3.5, -.007, 7.0 , “3 little pigs”, $CHAR(49), 0_"1".

  • Caché evaluates as False the value zero (0), and any nonnumeric value, including a null string ("") or a string containing a blank space (" "). Thus, the following all evaluate to False: 0, -0.0, “A”, “-”, “$”, “The 3 little pigs”, $CHAR(0), $CHAR(48), "0_1".

  • Standard Caché equivalence rules apply. Thus, the following evaluate to True: 0=0, 0="0", "a"=$CHAR(97), 0=$CHAR(48), and (" "=$CHAR(32)). The following evaluate to False: 0="", 0=$CHAR(0), and (""=$CHAR(32)).

In the following example, which WRITE command is executed depends on the value of the variable count:

 FOR count=1:1:10 {
   WRITE:count<5 count," is less than 5",!
   WRITE:count=5 count," is 5",!
   WRITE:count>5 count," is greater than 5",!
 }
FeedbackOpens in a new tab