欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Windows Powershell Do While 循環(huán)

 更新時間:2014年10月02日 12:21:44   投稿:hebedich  
Do和While可能產(chǎn)生死循環(huán),為了防止死循環(huán)的發(fā)生,你必須確切的指定循環(huán)終止的條件。指定了循環(huán)終止的條件后,一旦條件不滿足就會退出循環(huán)。

繼續(xù)與終止循環(huán)的條件

do-while()會先執(zhí)行再去判斷,能保證循環(huán)至少執(zhí)行一次。

復(fù)制代碼 代碼如下:

PS C:Powershell> do { $n=Read-Host } while( $n -ne 0)
10
100
99
2012
世界末日
為什么不退出
因為條件不滿足
怎樣才能滿足
請輸入一個0,試一試
0
PS C:Powershell>

單獨使用While

復(fù)制代碼 代碼如下:

$n=5
while($n -gt 0)
{
    $n
    $n=$n-1
}
5
4
3
2
1

終止當(dāng)前循環(huán)

使用continue關(guān)鍵字,可是終止當(dāng)前循環(huán),跳過continue后其它語句,重新下一次循環(huán)。

復(fù)制代碼 代碼如下:

$n=1
while($n -lt 6)
{
    if($n -eq 4)
    {
        $n=$n+1
        continue
 
    }
    else
    {
        $n
    }
    $n=$n+1
}
1
2
3
5

跳出循環(huán)語句

跳出循環(huán)語句使用break關(guān)鍵字

復(fù)制代碼 代碼如下:

$n=1
while($n -lt 6)
{
    if($n -eq 4)
    {
        break
    }
    $n
    $n++
}

相關(guān)文章

最新評論