Loop Structures

<< Click to Display Table of Contents >>

Navigation:  Reference (Scripting) > VBScript Basics > Control Structures >

Loop Structures

Do Until ...Loop

 

'Example

Do Until DefResp = vbNo

  MyNum = Int (6 * Rnd + 1)   ' Generate a random integer between 1 and 6.

  DefResp = MsgBox (MyNum & " Do you want another number?", vbYesNo)

Loop

 

 

Do...Loop While

 

'Example

Do

  MyNum = Int (6 * Rnd + 1)   ' Generate a random integer between 1 and 6.

  DefResp = MsgBox (MyNum & " Do you want another number?", vbYesNo)

Loop While DefResp = vbYes

 

 

While...Wend

 

'Example

Dim Counter

Counter = 0   ' Initialize variable.

While Counter < 20   ' Test value of Counter.

  Counter = Counter + 1   ' Increment Counter.

  DL.AddComment Counter

Wend   ' End While loop when Counter > 19

 

 

For...Next

 

'Example

For I = 1 To 5

    For J = 1 To 4

          For K = 1 To 3

              DL.AddComment I & " " & J & " " & K

          Next

    Next

Next