For ..... Next statement
Repeats a set of statements at a specified number of times.
For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next
Parameters
Counter
A numeric variable used as a loop counter. This variable cannot be an element of an array element or a user-defined type.
Start
The initial value of the counter.
End
The end value of the counter.
Step
The step size of the counter . If not specified, the default value for step is 1.
Statements
One or more statements between for and next will be executed a specified number of times.
Description
The step parameter can be positive or negative. The Step parameter value determines the execution of the loop, as follows:
value |
If ... The loop executes |
Positive or 0 |
Counter <= End |
Negative |
Counter >= End |
When the loop starts and all the statements in the loop are executed , the step value is added to the counter . At this point, or the statement in the loop executes again (the same test based on the loop beginning execution), or exits the loop and continues execution from the statement following the next statement.
note that changing the value of counter in the loop will make it more difficult to read and debug the program code.
Exit for can only be used for each ... Next or for ... NEXT structure, provides another way to exit the loop. You can place any Exit for statement anywhere in the statement. Exit for often is used with conditional judgment statements (for example, If ...). Then), and immediately transfers control to the statement after next .
You can put a for ... Next Loop is placed in another for ... Next Loop, which makes up a nested loop. The counter in each loop will use a different variable name. The following structure is correct:
for I = 1 to ten for J = 1 to ten for K = 1 to ten ... Next next Next