Directives
IF...THEN...ELSE Test Condition
   
Form 1. Set Conditions:

IF expression THEN ... [ELSE ...] [ END_IF ]

2. Set Conditions, Multiple Line Format:

IF expression THEN {
...
} [ELSE {...}]

Where:

... Statements to be processed.
{...} Curly brackets indicating statements within can span multiple lines.
expression An expression whose value determines if the condition is True or False.
In numeric expressions a zero value will indicate FALSE, otherwise any non-zero value will indicate TRUE.
In string expressions a null (empty or blank) value will indicate FALSE, otherwise any non-null value will indicate TRUE.

Use of a string expression is a +PxPlus Exclusive (Version 10)

Description Use the IF directive to control the execution of various ProvideX/PxPlus statements based on the result of a Boolean TRUE/FALSE value.

If the expression returns a TRUE value (non-zero for numeric, non-null for string) then ProvideX/PxPlus continues execution with the directives following the THEN clause up to the end of the statement, or until an ELSE clause is encountered. If the expression returns a FALSE value, execution of the statement continues with the directives following the ELSE clause (if you use it) or with the next statement.

You would normally include a logical operator (such as an equals sign =, less-than symbol <, etc.) in the numeric expression, but you can use any numeric expression. All statements within an IF..THEN..ELSE structure exist on the same line. These statements can only span multiple lines if they are enclosed within curly brackets. A matched set of open/closed brackets must be provided for each set of directives. Missed brackets can cause unexpected results.

Internally, when the system detects a { following the THEN clause it will continue execution up to the next } (if true) or skip forward to it (if false). The same holds true for the processing of the ELSE clause.

You can imbed multiple levels of multiple line IF directives using curly brackets; however, it is important not to lose consistency.

Using END_IF An optional END_IF (or FI) clause can be used to terminate the current IF structure and/or to execute a common closing statement. This is particularly useful for separating ELSE clauses in a nested IF..THEN..ELSE structure. Once the statements that follow an END_IF clause are executed, control will fall through to the next line, or (if nested) to the preceding level of IF..THEN..ELSE.
   
See Also END_IF End IF Directive.
   
Examples Simple IF Statement

00010 INPUT "Enter a number: ",a
00020 INPUT "Enter another: ",b
00030 IF a>b \
            THEN PRINT "First one is larger";
 
          STOP
00040 IF b>a \
 
          THEN PRINT "Second one is larger";
 
          STOP
00050 PRINT "Both numbers are the same"

00060 STOP
-:RUN
Enter a number: 123.45
Enter another: 123.56
Second one is larger

  Compound IF Statement:

00010 FOR i=1 TO 30
00020 PRINT i," is divisible by ",
00030 IF MOD(i,2)=0 \
            THEN IF MOD(i,3)=0 \
 
                      THEN PRINT "both" \ ELSE PRINT "2" \
 
                      ELSE IF MOD(i,3)=0 \ THEN PRINT "3" \
 
          ELSE PRINT "neither"
00040 NEXT i

00050 STOP RUN
1 is divisible by neither
2 is divisible by 2
3 is divisible by 3
4 is divisible by 2
...
28 is divisible by 2
29 is divisible by neither
30 is divisible by both

  Multiple Line IF Statement.

00010 IF A = B THEN {
00020 LET C = D
00030 PRINT "A equals B"
00040 } ELSE {
00050 LET X = Y
00060 PRINT "A was not identical to B"
00070 }