1、
#!/bin/bash
#0~100相加,for循环
declare -i i
declare -i sum
for i in {1..100};do
let sum+=i
let i++
done
echo $sum
2、
#!/bin/bash
#0~100相加,until循环
declare -i x=0
declare -i sum
until [ $x -gt 100 ]
do
let sum+=x
let x++
done
echo -e "the result is $sum"
3、
#!/bin/bash
#0~100相加,用while循环
declare -i x=0
declare -i sum
while((x<=100))
do
let sum+=x
let x++
done
echo $sum
时间: 2024-11-03 03:33:28