Thursday, September 2, 2010

Loop Statements in VBScript

Looping statements available in VBScript

Do...Loop: Loops while or until a condition is True
While...Wend: Loops while a condition is True
Syntax:
While condition
[statements]
Wend
For...Next: Uses a counter to run statements a specified number of times.
For Each ...Next: Repeats a group of statements for each item in a collection or each element of an array.

'Do ... While Statement
Count = 1
Do While Count <= 10 msgbox Count Count = Count + 1 Loop Do Statement
Count =1
Do
msgbox Count
Count = Count + 1
Loop While(Count <= 10)

'For...each statement

Dim Names(2)
Names(0) = "Tove"
Names(1) = "Jani"
Names(2) = "Hege"
For each Name in Names
msgbox (Name)
Next

'For statement
for counter = 0 to 5
msgbox "The counter value is "&counter
next

No comments:

Post a Comment