木子屋 Dnawo's BLOG

PowerShell的条件判断语句和循环语句

👤 dnawo 📅 2020-02-13 👁 4209 👍 0 💬 0 🔄 来源:本站原创
1、if条件判断语句

[b]if(1 -lt 2) { echo "true"} else {echo "false"}[/b]

true

2、for循环语句

[b]for($i=1;$i -le 5;$i++){echo $i}[/b]

1
2
3
4
5

3、while循环语句

[b]$i=1;for(;$i -le 5;){echo $i;$i++;}[/b]

1
2
3
4
5

4、foreach循环语句

[b]foreach($item in 1..5){echo $item}[/b]

1
2
3
4
5


参考资料

[1].Powershell IF-ELSE 条件:https://www.pstips.net/powershell-if-else-condition.html
[2].Powershell For 循环:https://www.pstips.net/powershell-for-loop.html
[3].Powershell Foreach 循环:https://www.pstips.net/powershell-foreach-loop.html
[4].从管道中删除对象:https://docs.microsoft.com/zh-cn/powershell/scripting/samples/removing-objects-from-the-pipeline--where-object-?view=powershell-7

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 设置Google在新标签页打开搜索结果的方法 下一篇 → 快剪辑APP从视频提取音乐和给视频录音方法图解