Merge pull request #677 from tardate/bash-while-loops

Clarify bash while examples and add example per #588
This commit is contained in:
Fechin authored and GitHub committed 2025-06-09 14:14:10 +08:00
commit 5893355de9
1 file changed
+29 -20
+29 -20
View File
@@ -515,26 +515,6 @@ for i in {5..50..5}; do
done
```
### Auto increment
```bash
i=1
while [[ $i -lt 4 ]]; do
echo "Number: $i"
((i++))
done
```
### Auto decrement
```bash
i=3
while [[ $i -gt 0 ]]; do
echo "Number: $i"
((i--))
done
```
### Continue
```bash {data=3,5}
@@ -569,6 +549,35 @@ until [ $count -gt 10 ]; do
done
```
### While with increment
```bash
i=1
while [[ $i -lt 4 ]]; do
echo "Number: $i"
((i++))
done
```
### While with decrement
```bash
i=3
while [[ $i -gt 0 ]]; do
echo "Number: $i"
((i--))
done
```
#### Combined with test
```bash
i=3
while ((i--)); do
echo "Number: $i"
done
```
### Forever
```bash