Excel vba中怎样实现类似continue,break等跳出循环的语句
2个回答
展开全部
Sub 提前退出循环()
Dim i As Integer
Dim sum As Integer
For i = 1 To 10
sum = sum + i
If sum > 20 Then
Exit For '满足条件提前结束for循环
End If
Next i
MsgBox "i=" & i & " sum= " & sum
End Sub
Sub 提前进行下一次循环()
Dim i As Integer
Dim arr
Dim str As String
arr = Array("我", "爱", "你", "中", "国")
For i = 0 To 4
If i = 2 Then
GoTo 忽略后面语句提前下一个 '提前进行后面的循环
End If
str = str & arr(i)
sum = sum + i
忽略后面语句提前下一个: Next i
MsgBox str '“我爱你中国”变成了“我爱中国”
End Sub
Dim i As Integer
Dim sum As Integer
For i = 1 To 10
sum = sum + i
If sum > 20 Then
Exit For '满足条件提前结束for循环
End If
Next i
MsgBox "i=" & i & " sum= " & sum
End Sub
Sub 提前进行下一次循环()
Dim i As Integer
Dim arr
Dim str As String
arr = Array("我", "爱", "你", "中", "国")
For i = 0 To 4
If i = 2 Then
GoTo 忽略后面语句提前下一个 '提前进行后面的循环
End If
str = str & arr(i)
sum = sum + i
忽略后面语句提前下一个: Next i
MsgBox str '“我爱你中国”变成了“我爱中国”
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询