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、嵌入式資料點擊:獲取資料
三、若是您以爲文章對您有幫助可轉至頁面上半部分打賞,或移步:打賞
四、或者在頁面右下角點推薦喲!!!
--------------------------------------------------------------分割線---------------------------------------------------------------