Flow control¶
Every program is a story about order. Structured blocks tell that story most clearly; line targets remain available when the original algorithm genuinely thinks in lines.
IF¶
Block form¶
IF Temperature# < 0 THEN
State$ = "ICE"
ELSEIF Temperature# < 100 THEN
State$ = "WATER"
ELSE
State$ = "STEAM"
END IF
Use as many ELSEIF arms as needed. ELSE is optional.
Single-line form¶
Single-line IF is good for a truly small choice. It becomes hard to scan once either arm has more than one idea.
Classic target forms are accepted too:
SELECT CASE¶
SELECT CASE is the readable answer when one value chooses among several shapes:
SELECT CASE Score%
CASE 100
Rank$ = "PERFECT"
CASE 80 TO 99
Rank$ = "EXCELLENT"
CASE IS >= 60
Rank$ = "PASS"
CASE 0, 1, 2
Rank$ = "JUST STARTED"
CASE ELSE
Rank$ = "TRY AGAIN"
END SELECT
A CASE can contain comma-separated exact values, inclusive value TO value ranges, or IS followed by a relation.
FOR ... NEXT¶
Use FOR when a counter and a limit describe the repetition:
STEP may be positive, negative, or computed:
NEXT may repeat the variable name. Doing so is useful in nested loops:
Leave early with EXIT FOR.
WHILE ... WEND¶
WHILE tests before the body:
If the condition begins false, the body does not run. EXIT WHILE provides an explicit early exit.
DO ... LOOP¶
DO supports top-tested and bottom-tested forms, with either WHILE or UNTIL:
A bottom-tested loop executes at least once. Use EXIT DO for an early escape.
Labels, GOTO, and GOSUB¶
A target is a numbered line or named label:
GOSUB remembers a return point; RETURN resumes there. Prefer a SUB when the routine needs parameters, local variables, a declared contract, or reuse across modules. GOSUB remains excellent for preserving the shape of a small classic listing.
Computed branches¶
ON expression GOTO and ON expression GOSUB choose a target by one-based position:
This is compact for transferred code. SELECT CASE is usually easier to extend safely in new code.
Procedure exits¶
The legal structured exits are:
An exit names the construct it leaves. There is no ambiguous unlabelled break that changes meaning when code is nested.
END and STOP¶
END completes a console program with status 0:
STOP is an intentional interruption and completes with status 3. It is useful while teaching, probing, or marking a path that should be conspicuous:
Neither is a refusal. A refusal is the runtime saying it cannot truthfully perform a requested operation.
Refusal control¶
ON REFUSAL GOTO target establishes the language's governed refusal handler. RESUME NEXT continues after the refused operation; RESUME target continues at an explicit target.
ON REFUSAL GOTO CouldNotProvide
CALL AskForOptionalCapability
PRINT "AVAILABLE"
GOTO Finished
CouldNotProvide:
PRINT "UNAVAILABLE:"; ERR; " AT "; ERL
RESUME Finished
Finished:
END
Use this for a truly optional runtime operation, not to hide programming mistakes or catch a pre-start admission failure. Errors, Refusals & Diagnostics explains catchability, recovery, and cleanup; Compatibility, Migration & Refusals explains the permanent machine-access boundary.
Next: Procedures & Functions →