Easytrieve Control Flow Overview

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.

Progress0 of 0 lessons

Sequential Default Versus Branching

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.

Decision Family — IF, ELSE-IF, ELSE

Decision statements
ConstructRoleTerminator
IFTest condition; run body when trueEND-IF (one per IF group)
ELSE-IFTest next condition when prior falseNone separate
ELSECatch-all when all above falseNone 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.

Loop Family — DO WHILE, DO UNTIL, WHILE, UNTIL

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.

text
1
2
3
4
5
6
DO WHILE IDX LE MAX-SLOTS IF SLOT-FLAG(IDX) EQ 'Y' PROCESS-SLOT END-IF IDX = IDX + 1 END-DO

Multi-Way Choice — CASE and SELECT

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.

Jumps — GOTO, EXIT, RETURN

Jump statements
StatementTypical use
GOTOJump to label—early loop exit, skip blocks
EXITLeave procedure or prescreen pass
RETURNEnd 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.

Control Flow in Activities

  • JOB — IF on file fields after GET; DO for array walks; GOTO JOB to skip remaining records.
  • PROGRAM — Shared decision logic across multiple JOB names; RETURN from procedures.
  • SCREEN — IF on PF keys and field validation; DO for repeating screen rows.
  • SORT BEFORE — IF with SELECT or EXIT; restricted statement set per sort prescreen rules.
  • Report procedures — IF in BEFORE-LINE; DO rare for generated lines.

Chapter Learning Path

  1. Control flow overview (this page) — map the territory.
  2. IF — conditions, nesting, ELSE-IF versus nested IF.
  3. ELSE — catch-all false branch semantics.
  4. DO — WHILE versus UNTIL, END-DO, infinite loops.
  5. WHILE — top-tested loops in depth.
  6. UNTIL, CASE, SELECT, Loops, EXIT, RETURN — complete the toolbox.

Statements Reference Versus Chapter Pages

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.

Common Control Flow Mistakes

Beginner pitfalls
MistakeFix
Missing END-IFMatch each IF with END-IF; indent nested blocks
Missing END-DOPair every DO with END-DO
DO WHILE when body must run onceUse DO UNTIL instead
Infinite loop—counter never changesIncrement INDEX inside body
ELSE-IF after ELSEELSE must be last branch before END-IF

Explain It Like I'm Five

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.

Exercises

  1. Label decision versus loop statements in a sample JOB excerpt.
  2. Draw flowchart for IF / ELSE-IF / ELSE / END-IF with three grade bands.
  3. Explain when DO UNTIL beats DO WHILE for read-then-test file logic.
  4. List five valid IF condition types from Broadcom documentation.
  5. Map which chapter page you would read next for multi-way status dispatch.

Quiz

Test Your Knowledge

1. Easytrieve primary decision structure is:

  • IF / ELSE-IF / ELSE / END-IF
  • SWITCH / CASE only
  • GOTO only
  • PERFORM

2. Loop statements in Easytrieve are:

  • DO WHILE and DO UNTIL with END-DO
  • FOR NEXT
  • LOOP ENDLOOP
  • REPEAT UNTIL keyword alone

3. WHILE in tutorial indexes maps to executable:

  • DO WHILE ... END-DO
  • WHILE ... END-WHILE
  • IF WHILE
  • SCREEN WHILE

4. After END-IF, execution continues:

  • At the next statement following END-IF
  • At the top of IF again
  • At END-JOB
  • Only in ELSE

5. Control flow statements run inside:

  • JOB, PROGRAM, SCREEN, and procedures
  • Library FILE defines only
  • JCL only
  • ENDTABLE only
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 IF, DO, GOTO, CASE, Control StatementsSources: Broadcom Easytrieve 11.6 IF Statement; DO Statement; GOTO; CASE; Program ActivitiesApplies to: Easytrieve control flow in batch and online programs