For...Next

From NSB App Studio
(Redirected from For...next)
Jump to: navigation, search

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 (Basic)

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

Example (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);
}

Output

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

Related Items

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