simulating_20continue
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| simulating_20continue [2018/03/31 13:19] – external edit 127.0.0.1 | 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> | ||
| WHILE some_condition | WHILE some_condition | ||
| REPEAT | REPEAT | ||
| Line 9: | Line 15: | ||
| UNTIL TRUE | UNTIL TRUE | ||
| 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.1522502383.txt.gz · Last modified: 2024/01/05 00:16 (external edit)