IF

The IF statement allows conditional execution of statements, based on various conditions. It replaces IF_SET as the generic "if" statement.

IF ( <Bool-expr> )

    Sequence of execution statements...

END_IF;

The sequence of statements will only be executed if the Boolean expression is true. Otherwise, they will be skipped. See earlier section for a detailed discussion of Boolean expressions.

IF ( <Bool-expr> )

    Sequence of execution statements for the TRUE case...

ELSE

    Sequence of execution statements for the FALSE case...

END_IF;

With the IF / ELSE form, it is possible to define two sequences of statements. One will be executed if the Boolean expression is true, while the other will be executed if the Boolean expression is false.

IF statements can be nested within each other in any combination and to any depth, as long as each one is properly terminated with an END_IF clause.

GPP Compatibility Notes:

In the old GPP, a major use of the IF_SET statement was to check if a variable is set to "on" or not. This can be best accomplished with the VAR_SET and VAR_NOTSET functions.

However, the old GPP did not have these functions. Instead, it allowed a simple syntax for that purpose, by simply writing IF_SET(X). While (X) is not really a Boolean expression, when used inside an IF_SET statement, it was interpreted by GPP to mean the set flag of X.

GPP2 maintains backward compatibility to the old GPP, and will also IF_SET(X) to mean IF(VAR_SET(X)).

Note that complex Boolean conditions must use the proper syntax, not the traditional shortcuts. For instance, IF_SET(X && Y) or IF(X && Y) is invalid. The GPP developer should use the full form IF(VAR_SET(X) && VAR_SET(Y)).

Example

IF (X_CENTER != 0)

  OUTPUT $ "I" X_CENTER;

END_IF;

IF (VAR_SET(X_CURPOS) && X_CURPOS < 100)

  OUTPUT $ "X" X_CURPOS;

  OLDX = X_CURPOS;

ELSE

  X_CURPOS = X_CURPOS + 1;

END_IF;

 

Note: Indentation of the statements inside an IF structure, as shown in these examples, is not mandatory. However, it is very useful in making the GPP program easier to read and understand. It is highly recommended to indent each level of nested IF statement, as follows:

IF (<expr>)

  IF (<expr>)

    Statements…

  ELSE

    Statements…

  END_IF;

END_IF;

Some functionality may be dependent on the product package. Contact your Reseller if you require a license.