Without control flow, every Easytrieve program would be a straight line: GET, MOVE, PRINT, repeat until EOF. Real payroll and inventory jobs branch on status codes, skip invalid rows, loop through array slots, and exit procedures early when prescreen rules fail. Control flow is the vocabulary for those forks and cycles—IF and ELSE for decisions, DO WHILE and DO UNTIL for loops, CASE and SELECT for multi-way choice, GOTO and EXIT for jumps, RETURN from procedures back to callers. Activities like JOB and SCREEN provide the stage; control flow writes the script inside each scene. Beginners who master only GET and PRINT still ship programs, but maintenance cost explodes when every exception becomes a duplicate JOB. This overview maps the control flow chapter: how decisions nest, when loops beat duplicated code, how statement reference pages relate to chapter tutorials, and how batch versus online activities share the same IF and DO syntax. Use it as the table of contents before diving into IF, ELSE, DO, and WHILE pages in this section.
Easytrieve executes statements in source order within an activity unless a control flow statement redirects. JOB INPUT loops imply read-process-print per record, but IF STATUS EQ 'D' can skip PRINT for deleted rows. DO WHILE IDX LE OCCURS-MAX walks array slots without unrolling MOVE statements. Understanding default sequential flow clarifies what IF and GOTO interrupt.
| Construct | Role | Terminator |
|---|---|---|
| IF | Test condition; run body when true | END-IF (one per IF group) |
| ELSE-IF | Test next condition when prior false | None separate |
| ELSE | Catch-all when all above false | None separate |
One END-IF closes the entire IF/ELSE-IF/ELSE group. ELSE-IF does not get its own END-IF. Nested IF requires an END-IF per nested IF. Chapter pages on IF and ELSE expand condition catalogs—EOF, MATCHED, DUPLICATE, field class tests—and contrast nesting with ELSE-IF chains.
Executable syntax is always DO WHILE or DO UNTIL ... END-DO. Tutorial indexes list WHILE and UNTIL as separate pages because developers search those terms. DO WHILE is top-tested—zero iterations possible. DO UNTIL is bottom-tested—at least one iteration. No counted DO n TIMES; build counters with INDEX or numeric fields inside the body. Loops chapter page ties WHILE, UNTIL, and nested patterns together.
123456DO WHILE IDX LE MAX-SLOTS IF SLOT-FLAG(IDX) EQ 'Y' PROCESS-SLOT END-IF IDX = IDX + 1 END-DO
CASE evaluates an expression and runs labeled WHEN branches—useful for status code dispatch. SELECT in control flow context (distinct from sort SELECT) handles other multi-path patterns per release documentation. Both reduce deep ELSE-IF ladders when values are discrete. Read CASE and SELECT chapter pages after mastering IF.
| Statement | Typical use |
|---|---|
| GOTO | Jump to label—early loop exit, skip blocks |
| EXIT | Leave procedure or prescreen pass |
| RETURN | End procedure and resume caller |
GOTO after END-DO exits loops when no BREAK exists. Overuse obscures logic—prefer IF and structured ELSE-IF when maintainers read your code. EXIT in sort BEFORE procedures ends prescreen without SELECT. RETURN pairs with PROC called from PERFORM-style flows.
Statements under /statements/if document Language Reference syntax for the IF verb. Chapter pages under /control-flow/if emphasize how IF fits JOB editing, audit tallies, and GOTO bypass patterns in beginner batch programs. Read both: reference for compile rules, chapter for job context.
| Mistake | Fix |
|---|---|
| Missing END-IF | Match each IF with END-IF; indent nested blocks |
| Missing END-DO | Pair every DO with END-DO |
| DO WHILE when body must run once | Use DO UNTIL instead |
| Infinite loop—counter never changes | Increment INDEX inside body |
| ELSE-IF after ELSE | ELSE must be last branch before END-IF |
Control flow is how the computer chooses what to do next. IF is a fork in the path: if it is raining, take the umbrella branch; otherwise keep walking. ELSE is the otherwise branch. DO is a merry-go-round: keep spinning while the music plays (WHILE), or spin until the bell rings (UNTIL). GOTO is jumping to a different spot on the playground when you are done with the merry-go-round early. Activities like JOB are different playgrounds; control flow is the rules on each playground.
1. Easytrieve primary decision structure is:
2. Loop statements in Easytrieve are:
3. WHILE in tutorial indexes maps to executable:
4. After END-IF, execution continues:
5. Control flow statements run inside: