Looping Statements in VBScript
(Page 1 of 4 )
As you begin to create more complex scripts with VBScript you will develop the need to repeat sections of your code in order to repeat some actions. Looping statements provide a device for repeating code segments.
VBScript provides several different looping statements that can be divided into two categories based on the way in which the loop is constructed: incremental loops and conditional loops.
Incremental loops are used to repeat code a definite number of times. The number of iterations is determined at the time the loop is created. This type of loop could be used to repeat a calculation a specific number of times or to move through each of the contents in an array since each of these would be repeated a definite number of times.
Conditional loops are used to repeat code based on the value of some conditional statement. In other words, the code would be repeated for as long as a specified condition is true or false. Looping will continue until that condition changes. This allows you to repeat code an indefinite number of times.
Looping structures are not to be confused with methods such as subroutines or functions. These alternate methods of repeating code are designed to allow code to be reused without looping. Viewing examples of both will make the separation between the two that much clearer.
More complex looping structures can be created by combining conditional loops and nesting multiple loops. As you become more familiar with looping structures and more experienced in their implementation, you will begin to see how these complex loops can be beneficial.
Next: Incremental Loops >>
More BrainDump Articles
More By Nilpo