Example 1 – Exit the Do While Loop When Specific Marks of a Student are Found In this example, we will find the student’s marks based on the student’s id and subject using a do-while conditional loop. Using the Exit Do command, when we find our desired value, we’ll exit the lo...
方法/步骤 1 Do循环的两种格式。(一)格式一:Do语句体[Exit Do]语句体Loop[while或until条件]2 示例:计算1-100之间正整数和。在EXCEL VBE中输入如下代码:Sub summation()n = 100Dim j As IntegerDim i As Integeri = 1Doj = j + ii = i + 1Loop Until i > 100MsgBox jEnd Sub运行程序,显示...
PS: Exit Do 仅可以用在 Do...Loop 循环语句中,提供另一种退出 Do...Loop 的方法。可以在 Do...Loop 语句中的任何位置放置任意个 Exit Do。Exit Do 通常与条件判断语句(如 If...Then )一起使用,将控制传递给紧随在 Loop 语句后面的语句。当用于嵌套 Do...Loop 中的时候,Exit Do 将控制传递给其...
Do Until循环与Do While循环的结构相似,最本质的区别在于循环条件的判断。顾名思义,在Do While循环中,当条件为真(True)时,就执行循环;而在Do Until循环中,执行循环直到条件为真(True)时,退出循环。 Do Until循环的基本语法结构如下: Do [Until条件语句] [语句...
1 1、do...Loop:循环语句,直至满足条件后退出。2 2、在VBE中编写代码:Sub doLoop()Dim a%Doa = a + 1If a > 10 Then Debug.Print ("a已经超过10了,该停止了!") Exit DoEnd IfLoopEnd Sub功能为:当a超过10时,将退出该程序。3 3、运行该代码,运行11次时,将输出a已经超过10了,该停止...
Exit For ' exit the loop if "date" is found End If Debug.Print Item Next Item End Sub Code Breakdown: We create an array of strings calledmyArrayusing theVBA Arrayfunction. The array contains five elements, which are the strings “apple“, “banana“, “cherry“, “date“, and “elde...
例如:Sub doWhile4()Dim I As Integer Do I = I + 1 '累加I变量值 Loop Until I = 10 'I等于10时,退出循环 End Sub 5.Do…Loop,没有任何条件,循环体中用If…Then…Else…End If语句判断,如果符合条件,用Exit Do语句退出循环。想了解更多精彩内容,快来关注OFFICE之门 ...
[Exit Do] 语句块2 Loop 首先判断循环条件,条件为真则执行Do到Loop之间的语句。 2、结尾判断循环条件 语句格式: Do 语句块1 [Exit Do] 语句块2 Loop While 循环条件 先执行一次Do到Loop之间的语句,再判断循环条件,满足条件则进行循环。 两种格式的区别:因为第二种格式是把循环体放在尾部,得先执行一遍语句再...
1、死循环让你的Excel瞬间卡死(循环语句之DO LOOP)关于循环语句,前面几节我们讲了:1)、在数字范围内循环for. next2)、在集合或者是数组范围内循环foreach. next本节我们来讲下,如果循环的范围不明确的时候应该用到的 语句:DOLOOP先来看一个例子:我想在A1单元格中演示数字从1开始循 环,step为1, 一直往下循...
可以在循环体中使用Exit For语句来退出循环。 5、 Do…Loop语句 可以使用Do…Loop语句循环执行其中的语句块,循环执行所用的时间是不确定的,当程序编制有错误时,容易进入死循环。所以一定要检查好循环中的跳出逻辑条件,当条件为True或直到条件变成True时,循环终止。