(十三)For...Next循环

这里写图片描述
注意:步长可以为负

Option Explicit
Dim i
For i=1 to 10 step 2
   Msgbox i
Next

For i=10to 5 step -1
  Msgbox i
Next

二、Exit For语句
用于在计数器达到终止值之前退出For…next 语句。因为通常只有在某些特殊情况下(例如发生错误时)要退出循环,
所以可以在If Then….Else语句的True语句块中使用Exit For语句;如果条件为False,循环将照常运行。

Option Explicit
Dim i
For i=1 to 10 step 2
   Msgbox i
If i>2 then
     Exit for
end If
Next
posted @ 2018-06-09 17:32  测试开发分享站  阅读(323)  评论(0编辑  收藏  举报