您现在的位置是:网站首页> 编程资料编程资料
Windows Powershell Do While 循环_PowerShell_
2023-05-26
376人已围观
简介 Windows Powershell Do While 循环_PowerShell_
继续与终止循环的条件
do-while()会先执行再去判断,能保证循环至少执行一次。
复制代码 代码如下:
PS C:Powershell> do { $n=Read-Host } while( $n -ne 0)
10
100
99
2012
世界末日
为什么不退出
因为条件不满足
怎样才能满足
请输入一个0,试一试
0
PS C:Powershell>
单独使用While
复制代码 代码如下:
$n=5
while($n -gt 0)
{
$n
$n=$n-1
}
5
4
3
2
1
终止当前循环
使用continue关键字,可是终止当前循环,跳过continue后其它语句,重新下一次循环。
复制代码 代码如下:
$n=1
while($n -lt 6)
{
if($n -eq 4)
{
$n=$n+1
continue
}
else
{
$n
}
$n=$n+1
}
1
2
3
5
跳出循环语句
跳出循环语句使用break关键字
复制代码 代码如下:
$n=1
while($n -lt 6)
{
if($n -eq 4)
{
break
}
$n
$n++
}
您可能感兴趣的文章:
相关内容
- Windows Powershell Foreach 循环_PowerShell_
- Windows Powershell ForEach-Object 循环_PowerShell_
- Windows Powershell Switch 语句_PowerShell_
- Windows Powershell IF-ELSEIF-ELSE 语句_PowerShell_
- Windows Powershell Where-Object 条件过滤_PowerShell_
- Windows Powershell条件表达式之条件操作符_PowerShell_
- Windows Powershell创建对象_PowerShell_
- Powershell小技巧之去除多余的空格_PowerShell_
- Powershell小技巧之创建短网址_PowerShell_
- Powershell小技巧之查找脚本中的函数_PowerShell_
