Windows Powershell Do While 循环
2019/7/10 21:24:54
本文主要是介绍Windows Powershell Do While 循环,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
继续与终止循环的条件
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 循环的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-09-14SharePoint 2019 用 PowerShell将启用发布功能站点网站集另存为模板
- 2022-08-30PowerShell教程 - 程序性能和BUG分析工具
- 2022-08-30PowerShell教程 - 模块管理(Modules Management)
- 2022-08-29PowerShell教程 - Web requests(Web请求)
- 2022-08-26PowerShell教程 - 日期时间管理(Date & Time Management)
- 2022-08-25PowerShell教程 - 磁盘与硬件管理(Disk & Hardware Management)
- 2022-08-25PowerShell教程 - 系统事件管理(System Event Management)
- 2022-08-25PowerShell教程 - 文件系统管理(File System Management)
- 2022-08-24PowerShell教程 - 网络管理(Network Management)
- 2022-08-24PowerShell