##if/##else/##endif [ VIRTUOSO CODE GENERATOR Reference Manual ] MPE/iX 5.0 Documentation
VIRTUOSO CODE GENERATOR Reference Manual
#if/#else/#endif
Instructs the generator to generate code if relational evaluations are
true or if boolean conditions are met.
Syntax
#if expression relop expression
or
#if (expression) boolean (expression)
statements
[#else
statements]
#endif
Keywords
expression is a literal value or a keyword. A literal text value
must be enclosed in quotes.
relop is one of the following relational operators:
=, <>, >, <, >=, <=
boolean is one of the following boolean operators:
AND, OR
statements are statements or user text lines.
Description
The #if construct instructs the generator to generate the code up through
the matching #endif or #else, if the expression evaluates to true. One
example of use of the #if construct is to determine if any relationships
were retrieved in the preceding #getrel or #for construct.
The #else is optional; however, the #endif must be included for every
invocation of the #if. The generator always matches an #else with the
nearest #if unmatched by an #endif. If the #else's and #endif's are
mismatched in number or location, an error is written to the listing
file.
Limitations. Comparisons are only valid where data types are the same.
You cannot compare a keyword of type numeric with a keyword of type
string or alphanumeric. For example:
#let a = "0" indicates "a" is type string
#let b = 0 indicates "b" is type numeric
therefore
#if a = b is an invalid statement
String comparisons are case-sensitive, and leading and trailing blanks
are significant. For example:
#let a = "PART-NUMBER"
#let b = "PART-NUMBER "
#let c = "part-number"
After the above statements, none of the three (a, b or c) are equal in
value.
Nesting of #if/#endif constructs is allowed, but remember that the
nesting limit is 40. That is, there cannot be more than 40 nesting
levels in existence at one time. This includes nesting of #for/#endfor,
#if/#endif, #include, #block/#endblock, #entry/#endentry and macros.
Examples
EXAMPLE 1
#if ELEMENT-TYPE="9"
When entering data values for !element, ensure that the data entered is
a numeric value from one to nine.
#endif
This documentation example illustrates the generation of text based on
the value of an attribute. If the element's type is 9, the text is
generated to describe that the data that an operator can enter must be
numbers rather than letters. Note here that the 9 is enclosed in quotes
since it is an ELEMENT-TYPE of type string, not numeric.
EXAMPLE 2
#if element:1 <> element:2
MOVE !element:1 TO !element:1!-BUFF
MOVE !element:2 TO !element:2!-BUFF
#else
MOVE DUP-FLAG TO DUP-INDICATOR
MOVE !element:1 TO !element:1!-BUFF
#endif
The above example illustrates comparing the values of two keywords. If
the value of element:1 is not equal to the value of element:2, the
statements following the #if construct are generated. Otherwise, the
statements following the #else are generated.
EXAMPLE 3
#getrel module="!module" image-database=? relclass="processes"
#if numrels <> 0
.
.
.
#endif
This example illustrates the use of the #if statement to determine if the
#getrel construct retrieved any relationships.
EXAMPLE 4
#let A=1
#if (A>5) or (A=1)
print "correct"
#else
print "wrong"
#endif
This example illustrates the use of the #if statement to check for one or
another condition.
MPE/iX 5.0 Documentation