As illustrated in the following table, there's nearly a one-to-one correspondence between VBScript and PowerShell constructs:
In VBScript… | In PowerShell… |
---|---|
Exit Do, Exit For | Break |
For…Next | For |
For Each…Next | Foreach |
Function | Function |
Sub | (no equivalent; use Function) |
If…Then | If |
If…ElseIf…Else | If, ElseIf, and Else |
Select…Case | Switch |
Do…Loop Until, Do Until…Loop | Do…until, Do until |
Do…Loop While, Do While…Loop | Do…While, While |
Refer to Chapter 8 to review the discussion of these loops and constructs.