手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >Windows Powershell Do While 循环
Windows Powershell Do While 循环
摘要:继续与终止循环的条件do-while()会先执行再去判断,能保证循环至少执行一次。复制代码代码如下:PSC:Powershell>do{$n...

继续与终止循环的条件

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 Do While 循环】相关文章:

Windows Powershell Foreach 循环

Windows Powershell使用管道

Windows Powershell 管道和重定向

Windows Powershell对象转换成文本

Windows Powershell Switch 循环

Windows Powershell使用哈希表

Windows Powershell属性:描述对象是什么

Windows PowerShell 微软官方解释

Windows Powershell分析和比较管道结果

Windows Powershell ForEach-Object 循环

精品推荐
分类导航