shell學習之路:流程式控制制(while)

來源:互聯網
上載者:User

標籤:

while迴圈:

介紹:while迴圈是不定迴圈,也稱作條件迴圈。只要條件判斷成立,迴圈就會一直繼續執行,直到條件判斷不成立,迴圈才會停止,這就是和for的固定迴圈不太一樣了、

1 while [ 條件判斷 ]2     do3         程式4     done

樣本:

 1 [[email protected] bash]# vi while1.sh 2 #!/bin/bash 3 #從1到100 4 i=1 5 s=0 6 while [ $i -le 100 ] ;do 7         s=$(( $s+$i )) 8         i=$(( $i+1 )) 9         done10 echo "The sum is :$s"11 [[email protected] bash]# chmod u+x while1.sh 12 [[email protected] bash]# ./while1.sh 13 The sum is :5050

2.until迴圈:

介紹:和while迴圈相反,until迴圈時只要條件判斷不成立,則執行,直到條件成立停止

 1 [[email protected] bash]# vi nutil1.sh 2 #!/bin/bash 3 i=1 4 s=0 5 until [ $i -gt 100 ] 6         do 7                 s=$(( $s+$i )) 8                 i=$(( $i+1 )) 9         done10 echo "The sum is :$s"11 [[email protected] bash]# chmod u+x nutil1.sh 12 [[email protected] bash]# ./nutil1.sh 13 The sum is :5050

OK

shell學習之路:流程式控制制(while)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.