linux-tutorial/codes/shell/demos/statement/while-demo.sh

21 lines
210 B
Bash
Raw Normal View History

2017-11-17 17:06:52 +08:00
#!/usr/bin/env bash
### 0到9之间每个数的平方
x=0
### x小于10
while [[ ${x} -lt 10 ]]; do
2019-10-10 08:56:31 +08:00
echo $((x * x))
x=$((x + 1))
2017-11-17 17:06:52 +08:00
done
2019-03-01 10:36:45 +08:00
# Output:
# 0
# 1
# 4
# 9
# 16
# 25
# 36
# 49
# 64
# 81