simulating_20continue
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
simulating_20continue [2018/04/17 18:48] – Added syntax highlighting tbest3112 | simulating_20continue [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Simulating CONTINUE===== | =====Simulating CONTINUE===== | ||
- | //by Richard Russell, November 2012//\\ \\ Some dialects of BASIC (e.g. Visual Basic) have a **CONTINUE** statement, which continues execution at the next iteration of a FOR, REPEAT or WHILE loop. It is equivalent to jumping to the NEXT, UNTIL or ENDWHILE statement (i.e. it skips the remainder of the ' | + | //by Richard Russell, November 2012, extended April 2022// |
+ | |||
+ | Many languages, including some dialects of BASIC (e.g. Visual Basic), have a **CONTINUE** or **CONT** statement, which continues execution at the next iteration of a FOR, REPEAT or WHILE loop. It is equivalent to jumping to the NEXT, UNTIL or ENDWHILE statement (i.e. it skips the remainder of the ' | ||
+ | |||
+ | The same effect may be achieved in BBC BASIC by using a GOTO, but obviously that isn't very satisfactory. A better way is to use a dummy REPEAT...UNTIL TRUE loop as follows: | ||
+ | |||
<code bb4w> | <code bb4w> | ||
WHILE some_condition | WHILE some_condition | ||
Line 11: | Line 16: | ||
ENDWHILE | ENDWHILE | ||
</ | </ | ||
+ | |||
+ | But this still isn't ideal: the indentation is confusing and EXIT REPEAT now exits from the dummy loop rather than from the outer loop (if that happens to be a REPEAT loop). | ||
+ | |||
+ | <code bb4w> | ||
+ | WHILE some_condition | ||
+ | REM Do some things | ||
+ | IF next_iteration THEN ENDWHILE WHILE FALSE : REM CONTINUE | ||
+ | REM Do some more things | ||
+ | ENDWHILE | ||
+ | </ | ||
+ | |||
+ | The **ENDWHILE WHILE FALSE** compound statement behaves to all intents and purposes exactly like CONTINUE. | ||
+ | |||
+ | <code bb4w> | ||
+ | REPEAT | ||
+ | REM Do some things | ||
+ | IF next_iteration THEN UNTIL FALSE REPEAT : REM CONTINUE | ||
+ | REM Do some more things | ||
+ | UNTIL some condition | ||
+ | </ | ||
+ | |||
+ | Unlike the WHILE case, however, this does have a flaw: it will not do the right thing if there' | ||
+ | |||
+ | <code bb4w> | ||
+ | REPEAT | ||
+ | REM Do some things | ||
+ | IF next_iteration THEN UNTIL FALSE REPEAT EXIT REPEAT : REM CONTINUE | ||
+ | REM Do some more things | ||
+ | UNTIL some condition | ||
+ | </ | ||
+ |
simulating_20continue.1523990932.txt.gz · Last modified: 2024/01/05 00:16 (external edit)