Skip to content

Commit 284caf2

Browse files
committed
Improve the learn about the statement of circulation ~
1 parent c45422b commit 284caf2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Descriptio : Nested loop.
2+
#Author : HuangYuhui
3+
#Date : January 17,2018
4+
5+
#!/bin/bash
6+
7+
for num in 1 2 3 4 5 6
8+
do
9+
for char in "a b c d e f"
10+
do
11+
echo $num $char
12+
done
13+
done
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#Description : Continue and break statement.
2+
#Author : HuangYuhui
3+
#Date : January 17,2018
4+
5+
#!/bin/bash
6+
7+
#Learn the contiune statement.
8+
#It's will be output : 4 5 6
9+
for var in 1 2 3 4 5 6
10+
do
11+
if [ $var -le 3 ];then #'-le' meaning : 'The condition is ture if the '$var' less than or equal to three'.
12+
continue
13+
fi
14+
echo "var=$var"
15+
done
16+
17+
#Learn the break statement.
18+
#It's will be output : 1 2
19+
a=1
20+
while [ $a -le 5 ] #'-le' meaning : 'less than or equal'.
21+
do
22+
if [ $a -eq 3 ];then #'-eq' meaning :'equal'
23+
break
24+
fi
25+
26+
echo "a=$a"
27+
a=$[ $a+1 ]
28+
done
29+
30+
echo "Break out of the inner loop with the break statement."
31+
a=1
32+
while [ $a -le 5 ]
33+
do
34+
echo "Outer loop output : a=$a"
35+
a=$[ $a+1 ]
36+
37+
for var in 1 2 3 4 5 6
38+
do
39+
if [ $var -eq 3 ];then
40+
break
41+
fi
42+
echo "Inner loop output : var=$var"
43+
var=$[ $var+1 ]
44+
done
45+
46+
done
47+
48+
echo "Break out of the multiple circulation with the break statement."
49+
a=1
50+
while [ $a -le 5 ]
51+
do
52+
echo "Outer loop output : a=$a"
53+
a=$[ $a+1 ]
54+
55+
for val in 1 2 3 4 5
56+
do
57+
if [ $val -eq 3 ]
58+
then
59+
break 2 #Break out of the while circulation.
60+
fi
61+
echo "Inner loop output : val=$val"
62+
val=$[ $val+1 ]
63+
done
64+
done
65+

0 commit comments

Comments
 (0)