USING-RANGE
Conditionally execute a statement with a range
WTSupported in traditional Synergy on Windows
|
WNSupported in Synergy .NET on Windows
|
USupported on UNIX
|
VSupported on OpenVMS
|
USING control RANGE low THRU high SELECT ([match_value[, ...]]), statement . . . ENDUSING
Arguments
control
An expression or single-character alpha literal whose value determines which statement is executed. (a or n)
low
A compile-time expression that specifies the lowest value within the range.
high
A compile-time expression that specifies the highest value within the range.
match_value
(optional) Defines a condition in which statement is executed, using any combination of the following formats:
A compile-time expression. A match occurs if control is equal to expression.
Two expressions separated by the THRU keyword. A match occurs if match_value is equal to or greater than exp_1 and less than or equal to exp_2.
An expression preceded by a relational operator. (See Operators for a list of operators.) Control is compared to exp by operator and evaluated for its truth value. If it’s true, a match occurs.
A match occurs if control was not matched by any literal match values, but was within the specified range.
A match occurs if control is outside the specified range.
statement
A Synergy DBL procedure division statement that is executed if one or more of the match_value expressions is true.
Discussion
The USING-RANGE statement selects a single statement for execution from a set of statements based on the value of a specified expression.
USING-RANGE builds a dispatch table at compile time and is faster than the USING statement. It is similar to the CASE statement, except that it provides more powerful structures.
Note the following difference between USING-RANGE and USING: in traditional Synergy, implied values used by control, low, high, and match_value are always rounded or truncated in the USING-RANGE statement. |
Any arithmetic that is done within a compile-time expression (low, high, or match_value) is whole number arithmetic and has the normal order of precedence. If the evaluated expression does not match one of the match_values, the statement immediately following the USING-RANGE statement is executed.
Not all of the values from low to high need to be specified. You can use the functions %INRANGE and %OUTRANGE to match any values that are not specified. A null match_value list (empty parentheses) matches any selection value within the range that is not specified or any value outside the range. A null list is equivalent to the match_value list (%INRANGE, %OUTRANGE).
Each match_value is evaluated from top to bottom and left to right. If the match_value falls outside of the range specified from low to high, the compiler warnings “Select value is outside defined range” (OUTOFRANGE) and “Statement can never be executed” (NOTEXE) are generated, and no match is set up for that value. If you specify an alpha literal longer than one character as your match_value, the compiler generates an “Only one character allowed” warning (ONEALPHA).
Once a match is found, no other conditions in the match_value list are evaluated.
If you use alpha labels with string control variables (and don’t compile with -qnoargnopt), be aware that the comparisons are .EQ. and .NE., which will be compared for the length of the shortest field. If you would like to match against the exact label, you should use the USING statement with the label (.EQS.“ABC”). Synergy .NET acts as if -qnoargnopt is set. |
See also
- CASE-ENDCASE statement
- USING-ENDUSING statement