While . . . Wend – Just another Looping Structure in VBScript

This does not have any special features other than what is explained with Do While . . . Loop.  This looping structure also works the same way like Do While . . Loop.  While . . . Wend is an older looping syntax and Do . . Loop is preferred over this.  The drawback of this loop is that there is no command to stop the execution in between using something like Exit For or Exit Do.

Syntax:

While {Condition}

– – – – – – – –

Block of code

– – – – – – – –

Wend

Example:

i=1
j=1
While i<20

        While j<i
            s=s&"*"
            j=j+1
        Wend

        s=s&vbnewline
  i=i+1
  j=1

Wend

msgbox s

Above example uses two While .. Wend loops and gives the output as a triangle of stars.

Output will be as below:

*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
**************

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.