user4119689
user4119689

Reputation:

How to loop a loop in VBScript?

I am trying to know how to, or even know if it is possible to, loop inside a loop in VBScript.

Here is what logically world work:

Do until y=5
msgbox "msgbox 1 loop test"
Do Until z=5
msgbox "msgbox 2 loop test"
z=z+1
loop
y=y+1
loop

That code should loop 'msgbox 2' 25 times and 'msgbox 1' 5 times but it doesn't.

I have yet to get an answer. This is my last resource of information so please help. Thanks

Upvotes: 3

Views: 2587

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

You need to initialize your variables:

y = 0
Do until y=5
    msgbox "msgbox 1 loop test " & y
    z = 0
    Do Until z=5
        msgbox "msgbox 2 loop test " & z
        z=z+1
    loop
    y=y+1
loop

Without z = 0 the second loop won't be entered after the first turn.

Upvotes: 2

Related Questions