当想要根据特定标准退出For循环时,就可以使用Exit For语句。当执行Exit For时,控件会立即跳转到For循环之后的下一个语句。

语法

以下是在VBA中Exit For语句的语法。

Exit For

流程图

示例

以下使用Exit For语句的示例。 如果计数器(i)的值达到4,则退出For循环,并在For循环之后立即跳转到下一个语句。

Private Sub Constant_demo_Click()
Dim a As Integer
a = For i = To a Step 'i is the counter variable and it is incremented by 2
MsgBox ("The value is i is : " & i)
If i = Then
i = i * 'This is executed only if i=4
MsgBox ("The value is i is : " & i)
Exit For 'Exited when i=4
End If
Next
End Sub

当执行上面的代码时,它将在消息框中输出以下输出。

The value is i is : 

The value is i is : 

The value is i is : 

The value is i is : 

最新文章

  1. .Net使用RabbitMQ详解
  2. Android之ListView性能优化——使用ConvertView和ViewHolder
  3. iOS开发零基础--Swift教程 可选类型
  4. Android 调用系统照相机拍照和录像
  5. java 对象传递 是 值传递 还是 引用传递?
  6. ChainOfResponsibility
  7. hdu 1718 Rank
  8. linux两台server远程copy文件
  9. 3.21 采购订单导入MDS
  10. Android中SharedPreferences介绍和使用方法
  11. spring MVC(十)---spring MVC整合mybatis
  12. SpringBoot系列——Redis
  13. EffectiveC++ 第5章 实现
  14. RedHat Enterprise Linux 6.4使用网易Centos 6 的yum源
  15. Oracle SQL Developer 调试存储过程步骤(Oracle)
  16. Java 一致性Hash算法的学习
  17. 使用jquery提交FormData数据
  18. python网络编程知识体系
  19. Mac下使用Eclipse的Show in Terminal提示command not found: mvn
  20. locatin

热门文章

  1. Python的开源人脸识别库:离线识别率高达99.38%(附源码)
  2. 十、collection的作用+变量
  3. ROS tf广播编写
  4. 009-Spring Boot全局配置跨域请求支持
  5. shell脚本中执行mysql sql脚本文件并传递参数
  6. laravel5.1框架model类查询实现
  7. DB2中ALTER TABLE的使用
  8. 把github代码自动部署到服务器
  9. axios发post请求,后端接收不到参数的问题
  10. RabbitMQ官方教程五 Topic(GOLANG语言实现)