For...Next: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
JwellsNB (talk | contribs)
No edit summary
 
Line 9: Line 9:
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 (Basic) ==
== Example ==


<pre>
<tabber>
Rem For...Next Example
JavaScript=
'For...Next repeats a group of statements
<syntaxhighlight lang="JavaScript">
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
</pre>
 
== Example (JavaScript) ==
<pre>
// For...Next Example
// For...Next Example
/* For...Next repeats a group of statements */
/* For...Next repeats a group of statements */
Line 37: Line 25:
   NSB.Print(i);
   NSB.Print(i);
}
}
</pre>
</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 ==

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