尽早突破循环 [英] Breaking out of a loop early
本文介绍了尽早突破循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
再次问好.
我下面有以下代码段:
Dim Ctr As Integer
Dim strX(16) As String
Sub modTwo()
With Word.Selection
Ctr = 1
Do
strX(Ctr) = "asdfasdfXasdfasdf"
.TypeText strX(Ctr)
If InStr(Ctr, strX(Ctr), "X", vbTextCompare) > 0 Then
Exit Do
End
End If
Ctr = Ctr + 1
Loop Until Ctr = 16
End With
End Sub
因此,这将产生输出:
Thus, this produces the output:
asdfasdfXasdfasdf
asdfasdfXasdfasdf
相反,我希望它根据条件产生输出:
Instead, I wanted it to produce the output based on the condition:
程序在字符串中读取X时,应尽早退出循环并结束程序.
When the program reads X within the string, it should exit the loop early and ends the program.
因此,这应该产生输出:
Thus, this should produce the output:
asdfasdfX
asdfasdfX
有答案吗?
此致
JohnDBCTX
JohnDBCTX
jp
推荐答案
John,
这是什么版本的VB?
这篇关于尽早突破循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文