For...Next: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
No edit summary
No edit summary
 
(5 intermediate revisions by 4 users not shown)
Line 11: Line 11:
== Example ==
== Example ==


<pre>
<tabber>
JavaScript=
<syntaxhighlight lang="JavaScript">
// 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);
}
</syntaxhighlight>
|-|
BASIC=
<syntaxhighlight lang="vb.net">
Rem For...Next Example
Rem For...Next Example
'For...Next repeats a group of statements
'For...Next repeats a group of statements
Line 22: Line 39:
   Print i
   Print i
Next
Next
</pre>
</syntaxhighlight>
</tabber>


== Output ==
== Output ==
Line 36: Line 54:
== Related Items ==
== Related Items ==


[[do...loop|DO...LOOP]], [[exit|EXIT]], [[for each...next|FOR EACH...NEXT]], [[while...wend|WHILE...WEND]]
[[do...loop|Do...Loop]], [[exit|Exit]], [[for each...next|For Each...Next]], [[while...wend|While...Wend]]


[[Category:Language Reference]]
[[Category:Language Reference]]
[[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