Vbscript-exit-for-statement
提供:Dev Guides
VBScript Exit Forステートメント
特定の基準に基づいて For ループを終了する場合は、 Exit For ステートメントが使用されます。 Exit For が実行されると、コントロールは For ループの直後に次のステートメントにジャンプします。
構文
VBScriptの Exit For ステートメントの構文は次のとおりです-
Exit For
流れ図
例
以下の例では、 Exit For を使用しています。 カウンタの値が4に達すると、Forループは終了し、Forループの直後に次のステートメントに制御がジャンプします。
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim a : a = 10
For i = 0 to a Step 2 'i is the counter variable and it is incremented by 2
document.write("The value is i is : " & i)
document.write("<br></br>")
If i = 4 Then
i = i*10 'This is executed only if i = 4
document.write("The value is i is : " & i)
Exit For 'Exited when i = 4
End If
Next
</script>
</body>
</html>
上記のコードが実行されると、コンソールに次の出力が出力されます。
The value is i is : 0
The value is i is : 2
The value is i is : 4
The value is i is : 40