|NO.Z.00026|——————————|LinuxShell|——|Linux&Shell&流程控制.V07|——|until循环|

一、until循环
### --- until循环语法
~~~     再来看看 until 循环,和 while 循环相反,
~~~     until 循环时只要条件判断式不成立则进行循环,并执行循环程序。
~~~     一旦循环条件成立,则终止循环。语法如下:

until [ 条件判断式 ]
    do
        程序
    done
二、until循环实验
### --- 实验一:还是写从 1 加到 100 这个例子,注意和 while 循环的区别:
~~~     例子:从 1 加到 100

[root@localhost ~]# vi sh/until.sh
#!/bin/bash
#从 1 加到 100
# Author: shenchao (E-mail: shenchao@atguigu.com)


i=1
s=0
#给变量 i 和变量 s 赋值
until [ $i -gt 100 ]
#循环直到变量 i 的值大于 100,就停止循环
        do
                s=$(( $s+$i ))
                i=$(( $i+1 ))
        done
echo "The sum is: $s"

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on 2022-03-26 23:11  yanqi_vip  阅读(16)  评论(0)    收藏  举报

导航