|
for next 语句
Sub for_test()
For i = 1 To 10 Step 1
If i > 5 Then
Exit For '跳出for循环
End If
Range("D" & i).Value = i '循环赋值给D1-D10
Next i
End Sub
for each 语句:用于为数组或集合中的每个元素
Sub for_ecah_test()
fruits = Array("苹果", "香蕉", "雪梨")
For Each Item In fruits
MsgBox (Item)
Next
End Sub
do while loop
Sub do_while_loop_test()
Do While i < 5 '在循环开始时,判断条件是否符合
If i > 3 Then
MsgBox ("跳出循环")
Exit Do
End If
i = i + 1
MsgBox ("The value of i is : " & i)
Loop
End Sub
Sub do_while_loop_test()
Do
If i > 3 Then
MsgBox ("跳出循环")
Exit Do
End If
i = i + 1
MsgBox ("The value of i is : " & i)
Loop While i < 5 '在循环结束时,判断条件是否符合
End Sub
|
|