- PowerShell 教程
- PowerShell - 主頁
- PowerShell - 概述
- PowerShell - 環境設定
- PowerShell - Cmdlet
- PowerShell - 檔案和資料夾
- PowerShell - 日期和定時器
- PowerShell - 檔案 I/O
- PowerShell - 高階 Cmdlet
- PowerShell - 指令碼編寫
- PowerShell - 特殊變數
- PowerShell - 運算子
- PowerShell - 迴圈
- PowerShell - 條件
- PowerShell - 陣列
- PowerShell - 雜湊表
- PowerShell - 正則表示式
- PowerShell - 反引號
- PowerShell - 括號
- PowerShell - 別名
- PowerShell 有用資源
- PowerShell - 快速指南
- PowerShell - 有用資源
- PowerShell - 討論
Powershell - 迴圈
你可能需要多次執行一段程式碼。通常,語句按順序執行:函式中的第一個語句首先執行,然後是第二個,以此類推。
程式語言提供了多種控制結構,允許執行更復雜的執行路徑。
迴圈語句允許我們多次執行語句或語句組,以下是在大多數程式語言中迴圈語句的一般形式 −
PowerShell 程式語言提供了以下型別的迴圈來處理迴圈需求。單擊以下連結檢視它們的詳細資訊。
| 序列號 | 迴圈和描述 |
|---|---|
| 1 | for 迴圈
多次執行一系列語句,並縮寫管理迴圈變數的程式碼。 |
| 2 | forEach 迴圈
增強型 for 迴圈。這主要用於遍歷元素集合,包括陣列。 |
| 3 | while 迴圈
在給定條件為真時,重複執行語句或語句組。它在執行迴圈體之前測試條件。 |
| 4 | do...while 迴圈
與 while 語句類似,不同之處在於它在迴圈體末尾測試條件。 |
廣告