while循环

【shell】while与until循环【shell】while与until循环

 

#!/bin/bash
i=1
s=0
while [  $i -le 100 ]
        do
                s=$(($s+$i))  ##变量运算
                i=$(($i+1))
        done

echo "1+2+3+...+100=$s"

  

 

until循环

【shell】while与until循环【shell】while与until循环

 

i=1
s=0
until [  $i -ge 100 ]  ##条件不成立才循环
        do
                s=$(($s+$i))
                i=$(($i+1))
        done

echo "1+2+3+...+100=$s"

  

相关文章: