Use parentheses to group conditions in more complex statements.
Using Loops, Using Loops, Using Loops
Another useful structure is the For...Next loop, which allows you to repeat
a series of commands a specified number of times:
SomeNumber = InputBox("How many lumps do you want?")
TotalLumps = ""
For i = 1 To SomeNumber
TotalLumps = TotalLumps & "lump "
Next
Rem -- The next line displays the result --
MsgBox TotalLumps
520 | Chapter 9: Scripting and Automation
The For...Next loop repeats everything between the two statements by
incrementing the value of the variable i until it equals the value of the variable
SomeNumber. Each time WSH goes through the loop, another ???lump??? is
added to the variable, TotalLumps. When the loop is finished, the contents of
the TotalLumps variable are displayed.
Notice the use of the concatenation operator (&) in the middle of the loop,
which adds a new lump to the variable. Those new to programming might
be put off by the fact that we have the TotalLumps variable on both sides of
the equals sign.* This works because the scripting host evaluates everything
on the right side of the equals sign (adds it all up) and then assigns it to the
variable on the left side.
Note also the TotalLumps="" statement before the For...Next loop; this empties
the variable before we start adding stuff to it. Otherwise, whatever might
be assigned to that variable before the loop would still be kept around??”
something we didn??™t anticipate or want.
Pages:
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723