IF; Unless LOGIC CONTROL

PURPOSE:  The control statements selectively control execution of a group of statements if the condition given is true.  The control statements are IF, UNLESS, ORIF, ORUNLESS, ELSE, and CONTINUE.

Syntax

{IF; UNLESS} [:n] conditions

[PM statement(s)]

[{ORIF; ORUNLESS} [:n] conditions]

[PM statements]

.

.

.

[ELSE[:n]]

PM statements

CONTINUE[:n]

:n

is a positive integer between 0 and 99999, indicating the level number of the given control statement.  If omitted, ACCENT R assumes it is level 0, which is the highest level.

IF condition

executes the following statements when the condition is true.

UNLESS

executes the following statements when the condition is false.

PM statements

can be any number of PM statements appropriate to the section in which the conditional is located.

ORIF condition

the condition is only checked if the preceding IF or ORIF statements of the same level failed.  There can be multiple ORIF statements.

ORUNLESS condition

the condition is only checked if the preceding UNLESS or ORUNLESS statements of the same level failed.  There can be multiple ORUNLESS statements.

ELSE

causes the following block of statements to be executed if the previously specified condition failed.

CONTINUE

terminates the current level.  Control passes to the CONTINUE statement immediately after successful completion of one of the above blocks at the same level.

Example

IF TITLE_CODE = "AB1000" OR "CC2001"
   QTY*PRICE TO YTD_SALES
ORIF TITLE_CODE = "XX9022"
   QTY-25 TO QTY
ORIF TITLE_CODE = “YY9022”
   QTY-30 TO QTY
CONTINUE

Note that ACCENT R must have evaluated the IF statement as false before it considers the ORIF statement.  If there are several ORIF statements, ACCENT R considers each condition until one evaluates as true.  It then executes the statements that follow and falls through to the CONTINUE.

UNLESS and ORUNLESS statements can be used in the same way as IF and ORIF statements, except ACCENT R executes the subsequent statements only when it evaluates the condition(s) as false. 

An ELSE statement can follow an IF, ORIF, UNLESS, or ORUNLESS  statement.  ACCENT R executes it when the condition(s) in the preceding IF or ORIF statement at the same level is false, or, in the case of a preceding UNLESS or ORUNLESS statement, when the condition(s) is (are) true. 

Example

IF QTY LT 100
   0 TO DISCOUNT
ORIF QTY GE 100 AND LT 500
   .1 TO DISCOUNT
ORIF QTY GE 500 AND LT 750
   .2 TO DISCOUNT
ELSE
   .3 TO DISCOUNT

ACCENT R executes the ELSE and subsequent statements only when none of the previous conditions are true.

A CONTINUE statement is used to terminate the effect of a group of control statements.  After a CONTINUE statement, ACCENT R executes all statements until processing reaches another control statement or the end of a section.  If the following two statements are added to the group above, the CONTINUE statement terminates the control of the preceding conditions.  Therefore, ACCENT R always executes the line following the CONTINUE.

CONTINUE
PRINT QTY,5B,DISCOUNT

The following example illustrates a nested structure.  The indented spacing is optional and is used here for clarity.

IF AUTHOR = "212-63-6699"
   IF:2 TITLE_CODE = "TR1717"
      TYPE "ROYALTY IS 10%"
   ELSE:2
      TYPE "ROYALTY IS 12%"
   CONTINUE:2
ELSE
      TYPE "INCORRECT AUTHOR"
CONTINUE

The IF and ELSE statements identified with level 2 are contained within the IF statement on level 0.  Another example of a nested structure follows:

IF @RN=BN
   IF:5 DATE<@DATE
   statement(s)
   ELSE:5
   statement(s)
ORIF @RN=TZ
   UNLESS:5 QTY=0
   statement(s)
   ELSE:5
   statement(s)
ELSE
statement(s)
CONTINUE

In this example, the control statements at level 5 are inner nests.  If the first condition ACCENT R executes either the statements after IF:5 or ELSE:5 and continues processing at the continue statement.  Or, if the condition @RN=TZ is true, ACCENT R executes one of the next two groups of statements and continues processing at the continue statement.  If neither condition is true, ACCENT R executes the statements after ELSE.  Finally, in any case, ACCENT R continues processing at the continue statement.

NOTES:  A nested structure may contain a nest within a nest.  Nests within nests are identified by level numbers.  All conditional statements that make up a level have the same level number.  Nests having larger level numbers are contained within nests having smaller level numbers.  Level 0 is the highest level.  It is the default level when none is specified.  Level numbers must be in ascending order.  They do not have to be consecutive.  Gaps in level numbers allows for insertions without having to renumber existing nests.

Nests are terminated by: 1) any control statement at the same or higher level; 2) the end of a process section; 3) the end of a ROUTINE; 4) a REPEAT statement at a higher level.

Nests may not overlap.  Two possible nests are shown below.  The one on the left is valid; the one on the right is not, because the ELSE:4 statement does not have a matching IF: 4 statement within the ORIF nest.

VALID NEST

INVALID NEST

IF condition
   IF:4 condition
        statement(s)
   ELSE:4
        statement(s)
   CONTINUE:4
ORIF condition
   statement(s)
IF:3 condition
   statement(s)
CONTINUE

IF condition
   IF:4 condition
        statement(s)
ORIF condition
   statement(s)
   ELSE:4 condition
   !nesting error
        statement(s)
   CONTINUE:4
CONTINUE

SEE ALSO:  START…REPEAT Loops, Conditional Clauses