码迷,mamicode.com
首页 > 编程语言 > 详细

VBA学习笔记之循环

时间:2017-08-05 20:36:09      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:until   containe   while   comm   pad   number   大于   line   code   

VBA 中Do while Loop用法如下:VBA中如果不知道重复多少次,使用 Do...Loop 语句。Do...Loop 语句重复执行某段代码直到条件是 true 或条件变成 true。重复执行代码直到条件是 true使用 While 关键字来检查 Do... Loop 语句的条件。

1
2
3
Do While i>10
  ‘some code
Loop

如果 i 等于 9,上述循环内的代码将终止执行。

1
2
3
Do
  ‘some code
Loop While i>10

这个循环内的代码将被执行至少一次,即使 i 小于 10。重复执行代码直到条件变成 true使用 Until 关键字来检查 Do...Loop 语句的条件。

1
2
3
Do Until i=10
  ‘some code
Loop

如果 i 等于 10,上述循环内的代码将终止执行。

1
2
3
Do
  ‘some code
Loop Until i=10

这个循环内的代码将被执行至少一次,即使 i 等于 10。退出 Do...Loop可以通过 Exit Do 关键词退出 Do...Loop 语句。

1
2
3
4
Do Until i=10
  i=i-1
  If i<10 Then Exit Do
Loop

这个循环内的代码,只要 i 不为 10 且 i 大于 10 时都将被执行。

VBA学习笔记之循环

标签:until   containe   while   comm   pad   number   大于   line   code   

原文地址:http://www.cnblogs.com/gilgamesh-hjb/p/7291222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!