内容:while语句
转载:WINCC脚本专栏
Do…Loop 语句
Do [{While | Until} 表达式]
语句
[Exit Do]
语句
Loop
或者
Do
语句
[Exit Do]
语句
Loop [{While | Until} 表达式]
第一种形式,当表达式为非0值(真)时,执行while循环体中的语句,如此往复,直到表达式的值等于0(假),循环结束。
如以下示例程序:
Dim index
index = 0
Do While index <= 10
document.write(index & " ")
index = index + 1
Loop
第二种形式的特点是使用 Until 关键字,先执行一次循环体语句,然后判断循环条件是否成立。当表达式为0值(假)时,返回重新执行循环体语句,如此往复,直到表达式的值等于非0(真)为止,循环结束。
如以下示例程序:
Dim index
index = 0
Do
document.write(index & " ")
index = index + 1
Loop Until index > 10
Exit Do 语句:
Exit Do语句可以用来从Do…Loop循环体内跳出循环体,即提前结束循环,接着执行循环语句下面的程序。
示例程序:
index = 0
Do While index <= 100
If index > 10 Then
Exit Do
End If
document.write(index & " ")
index = index + 1
Loop
在上面的示例中,当索引变量大于100时,条件将终止循环。但是,循环中的If语句将在索引变量大于10时使Exit Do语句终止循环。
还有While…Wend语句,功能与Do…Loop相同,较少使用。
转载请注明:XAMPP中文组官网 » VBScript语言程序控制语句——while