Regularity
From Maze
(Difference between revisions)
(→The Harmfulness of GOTO) | (Added that line number is optional in last variant.) | ||
| Line 219: | Line 219: | ||
<nowiki>10 FOR A=2 TO 10 STEP 2 | <nowiki>10 FOR A=2 TO 10 STEP 2 | ||
20 PRINT A | 20 PRINT A | ||
| − | 30 NEXT | + | 30 NEXT</nowiki> |
| − | </nowiki> | ||
If STEP is omitted, it's the same as adding "STEP 1." The step value can be set to a negative number or even to zero. By setting the value to 0, an unbounded FOR loop can be created: | If STEP is omitted, it's the same as adding "STEP 1." The step value can be set to a negative number or even to zero. By setting the value to 0, an unbounded FOR loop can be created: | ||
| Line 226: | Line 225: | ||
<nowiki>10 FOR A=1 TO 10 STEP 0 | <nowiki>10 FOR A=1 TO 10 STEP 0 | ||
20 PRINT "FOREVER!" | 20 PRINT "FOREVER!" | ||
| − | 30 NEXT | + | 30 NEXT</nowiki> |
| − | </nowiki> | ||
This allows for an alternate version of 10 PRINT, slightly longer but still a "one-liner" of no more than 80 characters, that uses a FOR loop instead of GOTO: | This allows for an alternate version of 10 PRINT, slightly longer but still a "one-liner" of no more than 80 characters, that uses a FOR loop instead of GOTO: | ||
| − | <nowiki>10 FOR A=1 TO 2 STEP 0 : PRINT CHR$(205.5+RND(1)); : NEXT | + | <nowiki>10 FOR A=1 TO 2 STEP 0 : PRINT CHR$(205.5+RND(1)); : NEXT</nowiki> |
| − | </nowiki> | + | |
| + | In fact, in this version the "10" at the beginning is optional. The three statements can be entered together in immediate mode, just as one can type <code>PRINT "HELLO"</code> and have the PRINT statement executed immediately: | ||
| + | |||
| + | <nowiki>10 FOR A=1 TO 2 STEP 0 : PRINT CHR$(205.5+RND(1)); : NEXT</nowiki> | ||
| + | |||
| + | The only reason the line number is needed in the original program is as a point to branch back to. As GOTO goes, so goes the line number. | ||
== Is 10 PRINT Iterating? == | == Is 10 PRINT Iterating? == | ||
