Until loop syntax format:
Until conditiondo statementdone Note: The condition when until enters the loop is: when the condition is not true, the loop is executed. The condition for until to enter the loop is exactly the opposite of while. The condition for while to enter the loop is: When condition is set, it enters the loop.
Example 1: WHILE LOOP
[[email protected] Learn]# cat while.sh #!/bin/bashdeclare -i sum=0declare -i i=0while [ $i -le 100 ]dolet sum+=$ilet i+=1doneecho $sum[[email protected] Learn]# ./while.sh 5050[[email protected] Learn]#
Example 2: Until Loop
[[email protected] Learn]# cat until.sh #!/bin/bashdeclare -i sum=0declare -i i=100until [ $i -eq 0 ]dolet sum+=$ilet i-=1doneecho $sum[[email protected] Learn]# ./until.sh 5050[[email protected] Learn]#
This article is from the "Hezhang" blog, please be sure to keep this source http://hezhang.blog.51cto.com/1347601/1439790