For...Next: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
(Created page with "FOR ''counter'' = ''start'' TO ''end'' [STEP ''step''] <br /> :::[''statements''] <br /> ::::[EXIT FOR] <br /> :::[''statements''] <br /> NEXT '''Description''' FOR...NEXT r...")
 
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
FOR ''counter'' = ''start'' TO ''end'' [STEP ''step''] <br />
For ''counter'' = ''start'' To ''end'' [Step ''step''] <br />
:::[''statements''] <br />
:::[''statements''] <br />
::::[EXIT FOR] <br />
::::[Exit For] <br />
:::[''statements''] <br />
:::[''statements''] <br />
NEXT
Next


'''Description'''
== Description ==


FOR...NEXT repeats a group of statements. The required component, ''counter'', is a number that can be used to reference the current iteration. The required components, ''start'' and ''end'', are the initial and final values of counter, each can be specified with any valid numeric expression. The optional parameter, ''step'', can be used to set the amount counter is incremented each loop, the default is 1. The optional component, ''statements'', will be executed as the body of the loop. Any number of optional EXIT FOR statements can be used to exit a loop before it is finished. FOR...NEXT statements can be nested, and any EXIT FOR statements in a nested loop transfer execution to one level above the loop where the EXIT FOR occurs.
For...Next repeats a group of statements. The required component, ''counter'', is a number that can be used to reference the current iteration. The required components, ''start'' and ''end'', are the initial and final values of counter, each can be specified with any valid numeric expression. The optional parameter, ''step'', can be used to set the amount counter is incremented each loop, the default is 1. The optional component, ''statements'', will be executed as the body of the loop. Any number of optional Exit FOR statements can be used to exit a loop before it is finished. For...Next statements can be nested, and any Exit For statements in a nested loop transfer execution to one level above the loop where the Exit For occurs.


'''Example'''
== Example ==


<pre>
<tabber>
REM FOR...NEXT Example
JavaScript=
'FOR...NEXT repeats a group of statements
<syntaxhighlight lang="JavaScript">
DIM Puppets
// For...Next Example
Puppets = ARRAY("Hat", "Twig")
/* For...Next repeats a group of statements */
FOR i = 0 to 1
 
   PRINT "Puppet: Mr. " & Puppets(i)
var Puppets;
NEXT
Puppets = new Array("Hat", "Twig");
FOR i = 0 to 10 STEP 5
for(i = 0; i <= 1; ++i) {
   PRINT i
  NSB.Print("Puppet: Mr. " + Puppets[i]);
NEXT
}
</pre>
for(i = 0; i <= 10; i += 5) {
  NSB.Print(i);
}
</syntaxhighlight>
|-|
BASIC=
<syntaxhighlight lang="vb.net">
Rem For...Next Example
'For...Next repeats a group of statements
Dim Puppets
Puppets = Array("Hat", "Twig")
For i = 0 to 1
   Print "Puppet: Mr. " & Puppets(i)
Next
For i = 0 to 10 STEP 5
   Print i
Next
</syntaxhighlight>
</tabber>


'''Output'''
== Output ==


<pre>
<pre>
Line 34: Line 52:
</pre>
</pre>


'''Related Items'''
== Related Items ==
 
[[do...loop|Do...Loop]], [[exit|Exit]], [[for each...next|For Each...Next]], [[while...wend|While...Wend]]
 
[[Category:Language Reference]]


[[do...loop|DO...LOOP]], [[exit|EXIT]], [[for each...next|FOR EACH...NEXT]], [[while...wend|WHILE...WEND]]
[[Category:Statements - Flow of control]]

Latest revision as of 15:11, 24 July 2019

For counter = start To end [Step step]

[statements]
[Exit For]
[statements]

Next

Description

For...Next repeats a group of statements. The required component, counter, is a number that can be used to reference the current iteration. The required components, start and end, are the initial and final values of counter, each can be specified with any valid numeric expression. The optional parameter, step, can be used to set the amount counter is incremented each loop, the default is 1. The optional component, statements, will be executed as the body of the loop. Any number of optional Exit FOR statements can be used to exit a loop before it is finished. For...Next statements can be nested, and any Exit For statements in a nested loop transfer execution to one level above the loop where the Exit For occurs.

Example

// For...Next Example
/* For...Next repeats a group of statements */

var Puppets;
Puppets = new Array("Hat", "Twig");
for(i = 0; i <= 1; ++i) {
  NSB.Print("Puppet: Mr. " + Puppets[i]);
}
for(i = 0; i <= 10; i += 5) {
  NSB.Print(i);
}

Rem For...Next Example
'For...Next repeats a group of statements
Dim Puppets
Puppets = Array("Hat", "Twig")
For i = 0 to 1
  Print "Puppet: Mr. " & Puppets(i)
Next
For i = 0 to 10 STEP 5
  Print i
Next

Output

Puppet: Mr. Hat
Puppet: Mr. Twig
0
5
10

Related Items

Do...Loop, Exit, For Each...Next, While...Wend