美文网首页
VBscript:控制流 - 循环 For/While/Unti

VBscript:控制流 - 循环 For/While/Unti

作者: 喷射的熔浆 | 来源:发表于2017-08-31 23:46 被阅读0次
flying-over-dolomites-by-arthur-cross

➿ 循环

🤞 for

⚽ 结构

For counter = start To end Step stepcount
    ...
    Exit For
    ...
Next

⚽ 举例

> CSCRIPT for-loop.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

1 3 5 7 9 11 13
17 19 21 23 25 27 29 31 33 35 37 39 41 43
47 49 51 53 55 57 59 61 63 65 67 69 71 73
77 79 81 83 85 87 89 91 93 95 97 99
'filename: for-loop.vbs
For num = 1 To 100 Step 2 'odd numbers
    If (num MOD 15) <> 0 Then
        Wscript.Stdout.Write num & " "
    Else
        Wscript.Echo ""
    End If
Next

🤞 for each

⚽ 结构

For Each element In Group
    ...
    Exit For
    ...
Next

⚽ 举例

> CSCRIPT for-each-loop.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files (x86)\Python36-32\Scripts\
C:\Program Files (x86)\Python36-32\
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\ProgramData\chocolatey\bin
C:\Program Files (x86)\Pandoc\
%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
%USERPROFILE%\.cargo\bin
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
C:\rakudo\bin
C:\rakudo\share\perl6\site\bin
C:\Program Files\Sublime Text 3
%USERPROFILE%\AppData\Local\Programs\Fiddler
%USERPROFILE%\AppData\Local\atom\bin
C:\Program Files\Microsoft VS Code\bin
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
C:\Program Files\Sublime Text 3
D:\PHP-7.1.7
'filename: for-each-loop.vbs
'Get
Set wshShell = CreateObject( "WScript.Shell" )
paths_str = wshShell.ExpandEnvironmentStrings("%PATH%")
paths = Split(paths_str,";")
'Display
For Each path In paths
  WScript.Echo path
Next

一个添加了排序的版本在 1

🤞 while

多用于读取文件,或等待特定状态

⚽ 结构

While condition(s)
   ...
Wend

⚽ 举例

...
...

🤞 do while

Do While condition
    ...
    Exit Do
    ...
Loop

🤞 do until

Do Until condition
    ...
    Exit Do
    ...
Loop

Reference

  1. Environment Variables

相关文章

网友评论

      本文标题:VBscript:控制流 - 循环 For/While/Unti

      本文链接:https://www.haomeiwen.com/subject/jggcjxtx.html