| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # wh-loopc.sh: Count to 10 in a "while" loop. |
| 3 | |
| 4 | LIMIT=10 # 10 iterations. |
| 5 | a=1 |
| 6 | |
| 7 | while [scip-shell system . . `[`. "$a" -le $LIMIT ] |
| 8 | do |
| 9 | echoscip-shell system . . echo. -n "$a " |
| 10 | let "a+=1" |
| 11 | done # No surprises, so far. |
| 12 | |
| 13 | echoscip-shell system . . echo.; echoscip-shell system . . echo. |
| 14 | |
| 15 | # +=================================================================+ |
| 16 | |
| 17 | # Now, we'll repeat with C-like syntax. |
| 18 | |
| 19 | ((a = 1)) # a=1 |
| 20 | # Double parentheses permit space when setting a variable, as in C. |
| 21 | |
| 22 | while (( a <= LIMIT )) # Double parentheses, |
| 23 | do #+ and no "$" preceding variables. |
| 24 | echoscip-shell system . . echo. -n "$a " |
| 25 | ((a += 1)) # let "a+=1" |
| 26 | # Yes, indeed. |
| 27 | # Double parentheses permit incrementing a variable with C-like syntax. |
| 28 | done |
| 29 | |
| 30 | echoscip-shell system . . echo. |
| 31 | |
| 32 | # C and Java programmers can feel right at home in Bash. |
| 33 | |
| 34 | exit 0 |