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

13 lines
252 B
Bash
Raw Normal View History

2019-03-01 10:36:45 +08:00
#!/usr/bin/env bash
# 查找 10 以内第一个能整除 2 和 3 的正整数
i=1
while [[ ${i} -lt 10 ]]; do
2019-10-10 08:56:31 +08:00
if [[ $((i % 3)) -eq 0 ]] && [[ $((i % 2)) -eq 0 ]]; then
echo ${i}
break;
fi
i=`expr ${i} + 1`
2019-03-01 10:36:45 +08:00
done
# Output: 6