The ELSE statement is the second half of a decision in Easytrieve. On its own, an IF statement says "when this condition is true, run these statements". ELSE adds the other side of that decision: "otherwise, run these statements instead". It identifies the block of logic that executes when the preceding IF condition - and any ELSE-IF conditions that follow the IF - are all false. ELSE is optional; a bare IF/END-IF is perfectly valid when you only want to act on the true case. But whenever your logic needs a genuine fork, where one path runs for a match and a different path runs for everything else, ELSE is the tool. Two properties of ELSE surprise newcomers coming from other languages. First, ELSE never carries a condition of its own - if you need to test something, that is what ELSE-IF is for. Second, ELSE has no terminator; the single END-IF that closes the IF also closes the ELSE. There is no END-ELSE keyword in the language. This tutorial explains how ELSE fits into the full IF/ELSE-IF/ELSE/END-IF family, when to choose ELSE versus ELSE-IF, how execution flows through each branch, how nesting works, and the coding habits that keep multi-branch decisions readable. Worked examples build from a simple two-way choice up to a chained decision with several bands and a final catch-all.
12345678910IF conditional-expression-1 [statement-1] [ELSE-IF conditional-expression-2] [ . . . ] [ [statement-2] ] [ELSE ] [ [statement-3] ] END-IF
ELSE appears near the bottom of the structure, after the IF and any ELSE-IF branches, and before the mandatory END-IF. Everything in square brackets is optional: you can have an IF with no ELSE at all, an IF with just an ELSE, or an IF with several ELSE-IF branches finished off by one ELSE. What you cannot do is put a condition on ELSE or give it its own terminator.
| Keyword | Has a condition? | Role |
|---|---|---|
| IF | Yes | Starts the decision and tests the first condition |
| ELSE-IF | Yes | Tests another condition when all previous ones are false |
| ELSE | No | Catch-all that runs when every condition above is false |
| END-IF | No | Closes the entire structure - exactly one per IF |
The most common use of ELSE is a plain either/or. The IF condition is tested; if it is true the first block runs, and if it is false the ELSE block runs. Exactly one of the two blocks executes every time - never both, never neither.
12345IF PAY-GROSS > 500.00 XMAS-BONUS = PAY-GROSS * 1.03 ELSE XMAS-BONUS = PAY-GROSS * 1.05 END-IF
Employees earning more than 500 get a 3 percent bonus; everyone else gets 5 percent. Because the two outcomes are mutually exclusive, ELSE is cleaner and faster than writing a second IF with the opposite condition, and it cannot accidentally leave the bonus unset.
The decision between ELSE and ELSE-IF comes down to a single question: do you have another condition to test? If yes, use ELSE-IF. If you simply want to handle everything that did not match, use ELSE. You can chain as many ELSE-IF branches as you need and finish with one ELSE that catches the remainder. Crucially, none of the ELSE-IF branches need their own END-IF - the whole chain is closed by a single END-IF, which is what keeps deeply banded logic from drowning in terminators.
1234567IF DIVISION = 'A' THRU 'L' DEDUCTIONS = GROSS * .15 ELSE-IF DIVISION = 'M' THRU 'R' DEDUCTIONS = GROSS * .2 ELSE DEDUCTIONS = GROSS * .18 END-IF
The first branch handles divisions A through L, the ELSE-IF handles M through R, and the ELSE handles every other division. Easytrieve tests the conditions top to bottom and runs the first one that is true; the ELSE only runs when both range tests fail.
Only one branch of an IF/ELSE structure ever executes. Easytrieve evaluates the IF condition first. If it is true, the IF block runs and control jumps straight to the statement after END-IF, skipping every ELSE-IF and the ELSE. If it is false, the next ELSE-IF is tested, and so on. If no condition is true, the ELSE block runs. There is no fall-through between branches as there is in some languages - you never need a break statement, and the branches cannot bleed into one another.
| Situation | Branch that executes |
|---|---|
| IF condition is true | The IF block only |
| IF false, first ELSE-IF true | That ELSE-IF block only |
| IF and all ELSE-IF false, ELSE present | The ELSE block |
| IF and all ELSE-IF false, no ELSE | No block - fall straight to after END-IF |
The statements inside an ELSE block can contain a complete IF/ELSE/END-IF of their own. This nesting lets you make a second decision only after the first one has gone the false way. Each nested IF needs its own END-IF, and lining up each ELSE under its matching IF is the single most important habit for keeping nested logic correct.
123456789IF ACCOUNT-STATUS = 'A' PERFORM PROCESS-ACTIVE ELSE IF ACCOUNT-BALANCE > 0 PERFORM SEND-TO-COLLECTIONS ELSE PERFORM CLOSE-ACCOUNT END-IF END-IF
Active accounts are processed immediately. For everything else, an inner decision checks the balance: a positive balance goes to collections, otherwise the account is closed. The inner END-IF closes the inner IF, and the outer END-IF closes the outer IF - two decisions, two terminators.
Imagine a fork in a path. The IF is a sign that asks a yes-or-no question. If the answer is yes, you take the first path. ELSE is the other path - the one you take when the answer is no. You always take exactly one path, never both. ELSE-IF is like extra signs along the way asking more questions before you finally reach the last plain path (the ELSE). And END-IF is the spot where all the paths join back together and you keep walking.
1. What does the ELSE statement identify in Easytrieve?
2. Does ELSE require its own terminator?
3. What is the difference between ELSE and ELSE-IF?
4. How many ELSE branches can a single IF have?
5. After the ELSE block finishes, where does execution continue?