Looping Statements in VBScript

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 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.