NEXT: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "NEXT is used in a FOR counter loop to progress through the loop count. {{PageSyntax}} : FOR {{Parameter|counterVariable}} = {{Parameter|startValue}} TO {{Parameter|stopValue}} [{{KW|STEP}} {{Parameter|increment}}] :: ''{code}'' :: ⋮ : NEXT [{{Parameter|counterVariable}}] {{PageDescription}} * NEXT is required in a FOR loop or a "FOR without NEXT" error will occur. * The FOR variable name is not required after N...") |
No edit summary |
||
Line 2: | Line 2: | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: [[FOR]] {{Parameter|counterVariable}} = {{Parameter|startValue}} [[TO]] {{Parameter|stopValue}} [{{KW|STEP}} {{Parameter|increment}}] | : [[FOR]] {{Parameter|counterVariable}} = {{Parameter|startValue}} [[TO]] {{Parameter|stopValue}} [{{KW|STEP}} {{Parameter|increment}}] | ||
:: ''{code}'' | :: ''{code}'' | ||
Line 10: | Line 10: | ||
{{PageDescription}} | {{PageDescription}} | ||
* [[NEXT]] is required in a FOR loop or a [[ERROR Codes|"FOR without NEXT" error]] will occur. | * [[NEXT]] is required in a FOR loop or a [[ERROR Codes|"FOR without NEXT" error]] will occur. | ||
* The FOR variable name is not required after [[NEXT]]. | * The FOR variable name is not required after [[NEXT]]. | ||
* [[NEXT]] can be grouped with other NEXTs in nested FOR loops using colons like [[NEXT]]: [[NEXT]] | * [[NEXT]] can be grouped with other NEXTs in nested FOR loops using colons like [[NEXT]]: [[NEXT]] | ||
Line 20: | Line 20: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' Finding the FOR variable value AFTER a simple counter loop to 10. | ''Example:'' Finding the FOR variable value AFTER a simple counter loop to 10. | ||
{{CodeStart}} | {{CodeStart}} | ||
FOR i = 1 TO 10 | FOR i = 1 TO 10 | ||
PRINT i; | PRINT i; | ||
NEXT i | NEXT i | ||
PRINT "AFTER the LOOP, NEXT makes the value of i ="; i | PRINT "AFTER the LOOP, NEXT makes the value of i ="; i | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} |
Revision as of 02:10, 23 January 2023
NEXT is used in a FOR counter loop to progress through the loop count.
Syntax
- FOR counterVariable = startValue TO stopValue [[[:Template:KW]] increment]
- {code}
- ⋮
- NEXT [counterVariable]
Description
- NEXT is required in a FOR loop or a "FOR without NEXT" error will occur.
- The FOR variable name is not required after NEXT.
- NEXT can be grouped with other NEXTs in nested FOR loops using colons like NEXT: NEXT
- NEXT can also end more than one nested FOR loop using comma separated variables like NEXT j, i
- NEXT increases the FOR loop count, so after the loop is over the counterVariable's value will be stopValue + 1 (or stopValue + increment).
- NEXT is also used with the RESUME statement.
Examples
Example: Finding the FOR variable value AFTER a simple counter loop to 10.
FOR i = 1 TO 10 PRINT i; NEXT i PRINT "AFTER the LOOP, NEXT makes the value of i ="; i |
1 2 3 4 5 6 7 8 9 10 AFTER the LOOP, NEXT makes the value of i = 11 |
Result: The last value of i = 11 although FOR only looped 10 times. Only use the count values while inside of the loop or compensate for this behavior in your code.
See also