|NO.Z.00025|——————————|LinuxShell|——|Linux&Shell&流程控制.V06|——|while循环|

一、while循环
### --- while循环语法
~~~     # 注:对 while 循环来讲,只要条件判断式成立,循环就会一直继续,
~~~     直到条件判断式不成立,循环才会停止。
~~~     好吧,我们还是写个 1 加到 100 的例子吧,
~~~     这种例子虽然对系统管理帮助不大,但是对理解循环非常有帮助:

while [ 条件判断式 ]
    do
        程序
    done
二、while实验
### --- 例子:1 加到 100

#!/bin/bash
#从 1 加到 100
# Author: shenchao (E-mail: shenchao@atguigu.com)


i=1
s=0
#给变量 i 和变量 s 赋值
while [ $i -le 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:10  yanqi_vip  阅读(23)  评论(0)    收藏  举报

导航