For...Next: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
For ''counter'' = ''start'' | For ''counter'' = ''start'' To ''end'' [Step ''step''] <br /> | ||
:::[''statements''] <br /> | :::[''statements''] <br /> | ||
::::[Exit For] <br /> | ::::[Exit For] <br /> |
Revision as of 01:09, 17 August 2012
For counter = start To end [Step step]
- [statements]
- [Exit For]
- [Exit For]
- [statements]
- [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
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