vbs不但提供了分支结构,还提供了丰富的循环形式。一共有3种循环:html
一、for循环数组
二、do...loop循环oop
三、while循环spa
各类循环有各自的特色,在使用的时候能够进行转换。code
前面已经描述过For循环,这里简单的描述一下后面两种循环。orm
1、Do....loop循环htm
Option Explicit 'do loop 循环 'do loop循环有两种形式 '一、形式1 while形式, while true 就一直循环 '二、形式2 until形式, until true 就中止循环 Dim bLoopAgain 'while形式的循环 '只要循环条件是true逻辑结果,就一直循环 Do Dim nInput bLoopAgain = False nInput= InputBox("请输入数值:","while形式循环") If Not IsNumeric(nInput) Then bLoopAgain = True End If Loop While bLoopAgain 'until形式的循环 '只要循环条件为true,就结束循环 Do bLoopAgain = false nInput = InputBox("请输入数值: ","until形式循环") If IsNumeric(nInput) Then bLoopAgain = True End If Loop Until bLoopAgain '同时do循环的while关键字还能够放在最前面 '造成下面的格式 'do while 逻辑结果 '循环语句 'loop bLoopAgain = True Do While bLoopAgain nInput = InputBox("请输入数值:","do while放在一块儿","") If IsNumeric(nInput) Then bLoopAgain = False End If Loop 'exit do循环语句 '有时候循环次数执行过多就跳出循环,比方说屡次输入的密码错误就不在执行 Dim strCipher Dim nInputCount nInputCount = 0 Do bLoopAgain = True nInputCount = nInputCount + 1 strCipher = InputBox("请输入密码:") If strCipher = "volcanol" Then bLoopAgain = False End If '若是输入密码的次数超过5次,那么就跳出循环 If nInputCount = 5 Then MsgBox "输入密码错误超过5次,禁止登录!",vbInformation,"提示" Exit Do End If Loop While bLoopAgain
二、while循环blog
'while... wend 循环 'vbs中还有一个比较简洁的循环语句, while....wend '这个循环当循环条件的逻辑结果为 true的时候一直循环 bLoopAgain = True While bLoopAgain If "volcanol" = InputBox("请输入密码:","输入") Then bLoopAgain = False End If Wend
3、Tipsip
一、集合和数组遍历可使用For循环ci
二、do循环要注意while和until的位置,两个须要注意
--------------------------------------------------------------分割线---------------------------------------------------------------
一、文章均为我的原创,欢迎转载,转载请保留出处:https://www.cnblogs.com/volcanol/
二、获取工控PLC、变频器、HMI、计算机、Windows、Linux、嵌入式资料点击:获取资料
三、若是您以为文章对您有帮助可转至页面上半部分打赏,或移步:打赏
四、或者在页面右下角点推荐哟!!!
--------------------------------------------------------------分割线---------------------------------------------------------------