Easytrieve UNTIL Control Flow

DO UNTIL implements bottom-tested control flow: statements in the loop body run, then the product evaluates the UNTIL condition; while the condition remains false, another iteration begins. That guarantees at least one execution—unlike DO WHILE which may skip the body entirely when the entry test fails. UNTIL fits process-then-decide designs: read a record before testing EOF, display a screen field before checking validity, or apply a formula before testing convergence. Syntax is DO UNTIL conditional-expression, body statements, END-DO. The condition expresses what you wait for to become true to stop looping—DO UNTIL EOF means keep going until EOF is true. Beginners invert conditions when translating from WHILE NOT EOF to UNTIL EOF. This page teaches bottom-tested flow diagrams, sentinel and EOF patterns, validation-after-input, UNTIL with counters, nesting with WHILE, conversion guidelines between loop styles, and production pitfalls when empty files must not process a phantom record—where WHILE may be safer with restructured read logic.

Progress0 of 0 lessons

Bottom-Tested Flow Explained

Control enters loop body immediately on first encounter with DO UNTIL. After body completes, condition evaluates. False means loop again; true means fall through to statement after END-DO. Flowchart shape is body-first diamond-after. Contrast WHILE diamond-before body. Choosing UNTIL documents intent to reviewers: this block always runs once minimum—a useful comment substitute in legacy shops.

WHILE versus UNTIL control flow
AspectDO WHILEDO UNTIL
Test timingBefore bodyAfter body
Minimum iterationsZeroOne
Continues whileCondition trueCondition false
Empty file read-in-bodyOften zero reads with pre-test EOFOne GET unless guarded

EOF Sentinel Pattern With UNTIL

Traditional pattern: DO UNTIL EOF MASTER, GET MASTER at top of body, process, END-DO. First GET runs before first EOF test—on empty file some layouts still set EOF immediately after GET, processing zero business records; verify EOF flag timing for your FILE type. Alternative: priming read before loop then DO WHILE NOT EOF with GET at end—WHILE variant avoids UNTIL empty-file nuance. Pick one pattern per shop and document EOF interaction with VB versus FB files.

text
1
2
3
4
5
6
7
JOB INPUT MASTER DO UNTIL EOF MASTER GET MASTER IF NOT EOF MASTER PERFORM PROCESS-RECORD END-IF END-DO

Validate-After-Process Control Flow

Online and batch validation sometimes must display or compute before knowing success. DO UNTIL VALID EQ Y with body that sets VALID after edits mirrors at-least-once semantics. Batch analog: compute TAX, DO UNTIL TAX GE MIN-TAX OR RETRIES GT 3, adjust, increment RETRIES, END-DO. Control exits when condition true—either tax sufficient or retry cap hit. Cap check in UNTIL prevents infinite adjustment loops.

Counted UNTIL Idiom

Less common than counted WHILE but valid: DO UNTIL CTR GE 10, body, CTR = CTR + 1, END-DO executes until CTR reaches 10—ten iterations if CTR starts 0 and increments each pass. Equivalence to DO WHILE CTR LT 10 depends on start value and increment placement. Prefer WHILE for counted loops unless bottom test documents stop-when-reached clearly.

Inverting Conditions Between WHILE and UNTIL

DO WHILE NOT EOF parallels DO UNTIL EOF with read-in-body restructuring. DO WHILE IDX LE MAX parallels DO UNTIL IDX GT MAX. When converting, write truth table for boundary values—IDX equals MAX is common off-by-one failure. Test both forms with same data in dev before refactoring production proc.

Nested UNTIL and Mixed Loops

Outer UNTIL inner WHILE appears when outer driver must process once per file section while inner skips zero detail lines. END-DO pairing must match nesting order. Mixed loops increase review burden— extract to PERFORM when possible. Screen programs rarely nest deep UNTIL; batch accumulators may nest UNTIL on control breaks with inner WHILE on array slots.

UNTIL With PERFORM and EXIT

PERFORM VALIDATE-ROW inside DO UNTIL NOT EOF; procedure EXIT when fatal error sets ABEND flag and UNTIL condition includes ABEND EQ N. EXIT from PROC does not exit UNTIL loop unless PERFORM returns and loop condition updated. Separate procedure flow from loop flow in design docs.

When UNTIL Is the Wrong Choice

  • Empty input must perform zero business logic—use WHILE or IF EOF before loop.
  • Optional block when flag starts N—WHILE FLAG EQ Y avoids one false iteration.
  • Search array with zero elements—WHILE IDX LE COUNT when COUNT may be 0.

Explain It Like I'm Five

DO UNTIL is do something, then ask are we done yet. You always do it at least once. Keep doing and asking until the answer is yes, we are done. DO WHILE asks first and might skip entirely. Pick UNTIL when the first turn always matters—like tasting soup once before deciding if it needs salt.

Exercises

  1. Rewrite DO WHILE NOT EOF read loop as DO UNTIL with IF guard.
  2. Truth table for CTR 0..10 on WHILE LT 10 versus UNTIL GE 10.
  3. Identify validate-after-process scenario in a payroll spec.
  4. Document shop standard EOF pattern choice with rationale.
  5. Find off-by-one risk in counted UNTIL loop.

Quiz

Test Your Knowledge

1. DO UNTIL always executes its body at least:

  • Once
  • Zero times
  • Ten times
  • Until compile error

2. DO UNTIL continues while:

  • Condition is false
  • Condition is true
  • EOF is true
  • STOP runs

3. UNTIL fits control flow when:

  • Body must run before first test
  • Body must never run
  • Only REPORT
  • No END-DO

4. DO UNTIL is closed by:

  • END-DO
  • END-UNTIL
  • END-IF
  • END-PROC

5. Sentinel-controlled input with read in body often uses:

  • DO UNTIL EOF or sentinel match
  • REPORT only
  • MACRO
  • PARM
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 DO UNTIL control flowSources: Broadcom Easytrieve 11.6 DO UNTIL StatementApplies to: Easytrieve UNTIL control flow design