巢狀迴圈
A nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes. a break within either the inner or outer loop would interrupt this process.
For Next 巢狀迴圈的結構是:
For counter1=startNumber to endNumber (Step increment)
For counter2=startNumber to endNumber (Step increment)
One or more VB statements
Next counter2
Next counter1
示例:
For firstCounter = 1 to 5
Print `First Loop of ` + firstCounter
For secondCounter= 1 to 4
Print `Second Loop of ` + secondCounter
Next secondCounter
Next firstCounter