1.条件判断语句
If Then Else
Sub judge(x)
If x = Then
MsgBox "the num is 0"
ElseIf x = Then
MsgBox "the num is 1"
ElseIf x = Then
MsgBox "the num is 2"
Else
MsgBox "the num is other"
End If
End Sub
judge()
2.Select case
Sub sel(x)
Select case x
case
MsgBox "the num is 1"
case
MsgBox "the num is 2"
case
MsgBox "the num is 3"
case
MsgBox "the num is 4"
End Select
End Sub
sel()
3.当条件满足为true时执行,循环do loop,先判断再做
Sub loo(i)
do while i <
MsgBox i
i=i+
loop
End Sub
4.当条件满足为true时执行,循环do loop,先做一次在判断
Sub loo(i)
do
MsgBox i
i=i+
loop while i <
End Sub
loo()
5.当条件为false执行,意思是直到i小于等于5都执行
Sub loo(i)
do until i >
MsgBox i
i=i+
loop
End Sub
loo()
6.先执行一次,当条件为false继续执行
do
MsgBox i
i=i+
loop until i >
End Sub
loo()
7.exit do可以终止循环
do until i >
MsgBox i
i=i+
exit do
loop
End Sub
loo()
8.while wend 不建议使用,用do loop
9.for next
for i= to UBound(Remark)
---
next
10.强行终止for,使用end for
for i = to
MsgBox i
if i> Then
exit for
End If
next
11.在不知道数组长度的时候使用for each
dim names()
names() = "George"
names() = "John"
names() = "Thomas"
for each x in names
MsgBox x
next
也可以使用exit for强行终止