PowerShell编程:循环、.NET框架交互及脚本编写全解析
1. 循环语句
在PowerShell中,循环语句是实现重复执行特定代码块的重要工具,主要有 while 、 do...while 和 do...until 三种类型。
1.1 while语句
while 语句的基本结构如下:
:loop_label while(condition)
{
statement block
}
当PowerShell执行 while 语句时,会先计算 condition 表达式的值。若该表达式的值为 $true ,则执行 statement block 中的代码块。只要 condition 的值一直为 $true ,代码块就会持续执行。示例代码如下:
$command = "";
while($command -notmatch "quit")
{
$command = Read-Host "Enter your command"
}
另外, break 和 continue </
超级会员免费看
订阅专栏 解锁全文
48

被折叠的 条评论
为什么被折叠?



