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.
- For . . . Next
- For Each . . . Next
- Do . . . . Loop
- While . . . . Wend
We will have a detailed discussion on each of the looping statements and also examples one-by-one in the next post.