Looping Statements in VBScript

by seetaram on August 27, 2011

Let us have a look at the following vbscript:

msgbox "Hello world"
msgbox "Hello world"
msgbox "Hello world"
msgbox "Hello world"
msgbox "Hello world"
msgbox "Hello world"
msgbox "Hello world"
msgbox "Hello world"

This is simply printing one message eight times.  This looks pretty simple!!! But, if we need to repeat 50 of such statements 100 times (iterations) how would it be? The code will be more complex to write as well as to debug and looks cluttered.

Following code does the same job in three lines:

For i=0 to 7
  msgbox "Hello World"
Next

This concept is termed as Loop in programming.

VBScript supports four types of looping statements.

  1. For . . . Next
  2. For Each . . . Next
  3. Do . . . . Loop
  4. While . . . . Wend

We will have a detailed discussion on each of the looping statements and also examples one-by-one in the next post.

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email