Windows Powershell Do While 循环
继续与终止循环的条件
do-while()会先执行再去判断,能保证循环至少执行一次。
PSC:Powershell>do{$n=Read-Host}while($n-ne0)
10
100
99
2012
世界末日
为什么不退出
因为条件不满足
怎样才能满足
请输入一个0,试一试
0
PSC:Powershell>
单独使用While
$n=5
while($n-gt0)
{
$n
$n=$n-1
}
5
4
3
2
1
终止当前循环
使用continue关键字,可是终止当前循环,跳过continue后其它语句,重新下一次循环。
$n=1
while($n-lt6)
{
if($n-eq4)
{
$n=$n+1
continue
}
else
{
$n
}
$n=$n+1
}
1
2
3
5
跳出循环语句
跳出循环语句使用break关键字
$n=1
while($n-lt6)
{
if($n-eq4)
{
break
}
$n
$n++
}
热门推荐
10 情侣祝福语古文简短独特
11 酒店伴娘祝福语简短
12 晚上甜蜜的祝福语简短
13 给新娘简短的祝福语
14 当爸爸的简短祝福语
15 洛宁新年祝福语大全简短
16 新年祝福语简短搞笑幽默
17 结婚祝福语大全简短霸气
18 新人结婚祝福语简短高端