| **Navigation:**  [[introduction.htm|Language Reference]] > 12 - Execution Control > Control Structures >====== IF (conditional execution structure) ====== | [[execute statement execution structure .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[loop iteration structure .htm|{{btn_next_n.gif|Next page}}]] | | || ** ** **IF** //logical expression// [** THEN **] //statements// [** ELSIF** //logical expression //[** THEN **] //statements //] [** ELSE** //statements //] **END** {{blk2blue.jpg|blk2blue.jpg}} | **IF** | Initiates a conditional statement execution structure. | | //logical expression// | A variable, procedure, or expression which evaluates a condition. Control is determined by the result (true or false) of the expression. Zero (or blank) evaluates as false, anything else is true. | | **THEN** | The //statements// following THEN execute when the preceding //logical expression// is true. If used, THEN must only appear on the same line as **IF** or **ELSIF**. | | //statements// | An executable statement, or a sequence of executable statements. | | **ELSIF** | The //logical expression// following an **ELSIF** is evaluated only when all preceding **IF** or **ELSIF** conditions were evaluated as false. | | **ELSE** | The //statements// following **ELSE** execute only when all preceding **IF** and **ELSIF** options evaluate as false. ELSE is not required, however, when used, it must be the last option in the IF structure. | An **IF** structure controls program execution based on the outcome of one or more //logical expressions//. IF structures may have any number of ELSIF statement groups. IF structures may be "nested" within other executable structures. Other executable structures may be nested within an IF structure. Each IF structure must terminate with an END statement (or period). **Example:** **IF**** Cus:TransCount = 1                              !If new customer** ** AcctSetup                                         !call account setup procedure** **ELSIF Cus:TransCount > 10 AND Cus:TransCount <; 100 !If regular customer** ** DO RegularAcct                                    !process the account** **ELSIF Cus:TransCount > 100                         !If special customer** ** DO SpecialAcct                                    !process the account** **ELSE                                               !Otherwise** ** DO NewAcct                                        !process the account** ** IF Cus:Credit** **  CheckCredit** ** ELSE** **  CLEAR(Cus:CreditStat)** ** END** ** ! verify credit status** **END     ** **IF ERRORCODE()** ** ErrHandler(Cus:AcctNumber,Trn:InvoiceNbr)         !Handle errors** **END** **See Also:** [[execute statement execution structure .htm|EXECUTE]] [[case selective execution structure .htm|CASE]]