📜  Powershell-循环

📅  最后修改于: 2020-11-19 07:59:45             🧑  作者: Mango


在某些情况下,您需要多次执行一个代码块。通常,语句是按顺序执行的:函数的第一个语句首先执行,然后第二个执行,依此类推。

编程语言提供了各种控制结构,允许更复杂的执行路径。

循环语句使我们可以多次执行一个语句或一组语句,以下是大多数编程语言中循环语句的一般形式-

循环架构

PowerShell编程语言提供以下类型的循环来处理循环需求。单击以下链接以查看其详细信息。

Sr.No. Loop & Description
1 for loop

Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.

2 forEach loop

Enhanced for loop. This is mainly used to traverse collection of elements including arrays.

3 while loop

Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

4 do…while loop

Like a while statement, except that it tests the condition at the end of the loop body.