If, End, and EndExit Commands
The If command tests a condition. If the condition is true, one or more lines of logic is executed. A condition tests the relationship between two values. The operators you can use to test a condition are listed in the following table:
Operator | Meaning | Example |
---|---|---|
< | Less than | If Sale.Price < 10000 |
NOT < | Not less than | If Sale.Price NOT < 10000 |
> | Greater than | If Sale.Price > 30 |
NOT > | Not greater than | If Sale.Price NOT > 30 |
= | Equal to | If Sale.CustType = “A” |
NOT = | Not equal to | If Sale.CustType NOT = “A” |
NUMERIC | Is numeric | If myNum NUMERIC |
<= | Less than or equal to (not greater than) | If Sale.Price <= 10000 |
>= | Greater than or equal to (not less than) | If Sale.Price >= 10000 |
You can also test for more than one condition in a statement by combining conditions. The logical operators you can use to test compound conditions are listed in the following table:
Operator | Meaning | Example |
---|---|---|
NOT (~) | Logical NOT | If ~ Sale.CustType = “A” |
AND (&&) | Logical AND | If numC = 3 && numB = 25 |
OR (||) | Logical OR | If Sale.CustType = “A” || Sale.Price < 10000 |
In compound conditions, NOT operators are evaluated first, followed by AND operators and then OR operators.
Compound conditions require only one End, EndNoPrint, or EndExit command, as they create a single logical condition. introduced by a condition or a loop.
The EndExit command is similar to the End command in that it defines the end of a block of logic introduced by a condition or a loop. When an EndExit command terminates a loop, no further passes are made through the loop. When an EndExit command is executed in a unit of logic, all remaining logic in that unit is skipped.
Closing logic blocks with EndExit checks for business processing errors. When an error is encountered, an error message is displayed and the logic terminates. If logic flow passes the error checks, the logic following the error checks is executed.