for 迴圈
在經典 ASP 中,我們可以使用 for 關鍵字指定 for 迴圈。使用 for 語句,我們需要下一個語句來增加計數器。
For i = 0 To 10
Response.Write("Index: " & i)
Next
該步關鍵字可以用來改變該怎麼下一個宣告將修改計數器。
For i = 10 To 1 Step -1
'VBS Comment
Next
要退出 for 迴圈,請使用 Exit For 語句
For i = 0 To 10
Response.Write("Index: " & i)
If i=7 Then Exit For 'Exit loop after we write index 7
Next
我們還可以使用 For...Each
迴圈來執行集合中一系列已定義元素的迴圈。例如:
Dim farm, animal
farm = New Array("Dog", "Cat", "Horse", "Cow")
Response.Write("Old MacDonald had a Farm, ")
For Each animal In farm
Response.Write("and on that farm he had a " & animal & ".<br />")
Next