Entry
BBCBASIC: Program: Control structure: Loop: How to possibly quit a REPEAT UNTIL control structure?
Jan 28th, 2006 12:42
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 28 January 2021 - 05:36 pm --------------------
BBCBASIC: Program: Control structure: Loop: How to possibly quit a
REPEAT UNTIL control structure?
---
A general construct to quit a 'REPEAT UNTIL' loop could
be the following:
Steps: Overview:
1. -Create a common variable to test if you have to stop
when arriving at the UNTIL and set it to FALSE
stopB% = FALSE
2. -Create a separate Boolean variable for all the possible
breakpoints and set them to FALSE
stop1B% = FALSE
stop2B% = FALSE
...
stopLastB% = FALSE
3. -Inside the REPEAT UNTIL loop set the corresponding Boolean
variable to TRUE if you want to quit the loop
e.g.
stop2B% = TRUE
4. -If any of this Boolean variables is TRUE, you want to quit
the loop
stopB% = stop1B% OR stop2B% OR stop3B% OR ... OR stopLastB%
making stopB% TRUE
5. -If stopB% is TRUE, you quit the loop
===
--- cut here: begin --------------------------------------------------
stopB% = FALSE
:
stop1B% = FALSE
stop2B% = FALSE
...
stopLastB% = FALSE
:
REPEAT
do something 1 and let stop1B% = TRUE
do something 2 and let stop2B% = TRUE
...
do something last and let stoplastB% = TRUE
...
stopB% = stop1B% OR stop2B% OR stop3B% OR ... OR stopLastB%
UNTIL stopB%
:
END
--- cut here: end ----------------------------------------------------
===
E.g.
--- cut here: begin --------------------------------------------------
stopB% = FALSE
:
stop1B% = FALSE
:
I% = 1 - 1
REPEAT
I% = I% + 1
PRINT I%
IF I% >= 2 THEN stop1B% = TRUE
stopB% = stop1B%
UNTIL stopB%
END
--- cut here: end ----------------------------------------------------
===
E.g.
--- cut here: begin --------------------------------------------------
stopB% = FALSE
:
stop1B% = FALSE
stop2B% = FALSE
:
I% = 1 - 1
J% = 1 - 1
REPEAT
I% = I% + 1
J% = J% + 1
PRINT I%, J%
IF I% >= 2 THEN stop1B% = TRUE
IF J% >= 2 THEN stop2B% = TRUE
stopB% = stop1B% OR stop2B%
UNTIL stopB%
END
--- cut here: end ----------------------------------------------------
===
E.g.
--- cut here: begin --------------------------------------------------
stopB% = FALSE
:
stop1B% = FALSE
stop2B% = FALSE
stop3B% = FALSE
:
I% = 1 - 1
J% = 1 - 1
K% = 1 - 1
REPEAT
I% = I% + 1
J% = J% + 1
K% = K% + 1
PRINT I%, J%, K%
IF I% >= 2 THEN stop1B% = TRUE
IF J% >= 2 THEN stop2B% = TRUE
IF K% >= 3 THEN stop3B% = TRUE
stopB% = stop1B% OR stop2B% OR stop3B%
UNTIL stopB%
END
--- cut here: end ----------------------------------------------------
===
E.g.
--- cut here: begin --------------------------------------------------
stopB% = FALSE
:
stop1B% = FALSE
stop2B% = FALSE
stop3B% = FALSE
stop4B% = FALSE
:
REPEAT
PRINT; "command = ";
INPUT s$
IF s$ = "break1" THEN stop1B% = TRUE
IF s$ = "break2" THEN stop2B% = TRUE
IF s$ = "break3" THEN stop3B% = TRUE
IF s$ = "quit" THEN stop4B% = TRUE
stopB% = stop1B% OR stop2B% OR stop3B% OR stop4B%
UNTIL stopB%
END
--- cut here: end ----------------------------------------------------
===
E.g.
--- cut here: begin --------------------------------------------------
stopB% = FALSE
:
stop1B% = FALSE
stop2B% = FALSE
stop3B% = FALSE
stop4B% = FALSE
:
REPEAT
PRINT; "command = ";
INPUT s$
IF s$ = "break1" THEN stop1B% = TRUE
IF s$ = "break2" THEN stop2B% = TRUE
IF s$ = "break3" THEN stop3B% = TRUE
IF s$ = "quit" THEN stop4B% = TRUE
stopB% = stopB% OR stop1B%
stopB% = stopB% OR stop2B%
stopB% = stopB% OR stop3B%
stopB% = stopB% OR stop4B%
UNTIL stopB%
END
--- cut here: end ----------------------------------------------------
---
---
Internet: see also:
---
----------------------------------------------------------------------