Debian Codegraph @

ex28.sh

raw symbols SCIP
1 #!/bin/bash
2
3 LIMIT=19 # Upper limit
4
5 echo
6 echo "Printing Numbers 1 through 20 (but not 3 and 11)."
7
8 a=0
9
10 while [ $a -le "$LIMIT" ]
11 do
12 a=$(($a+1))
13
14 if [ "$a" -eq 3 ] || [ "$a" -eq 11 ] # Excludes 3 and 11.
15 then
16 continue # Skip rest of this particular loop iteration.
17 fi
18
19 echo -n "$a " # This will not execute for 3 and 11.
20 done
21
22 # Exercise:
23 # Why does the loop print up to 20?
24
25 echo; echo
26
27 echo Printing Numbers 1 through 20, but something happens after 2.
28
29 ##################################################################
30
31 # Same loop, but substituting 'break' for 'continue'.
32
33 a=0
34
35 while [ "$a" -le "$LIMIT" ]
36 do
37 a=$(($a+1))
38
39 if [ "$a" -gt 2 ]
40 then
41 break # Skip entire rest of loop.
42 fi
43
44 echo -n "$a "
45 done
46
47 echo; echo; echo
48
49 exit 0