Skip to content

Commit dec1bce

Browse files
committed
updated Ch05
1 parent 5fda3cd commit dec1bce

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Ch05-Iterations.ipynb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"life is full of loops; everyday routines such as going to college, cooking food, slicing vegetables, etc.\n",
99
"\n",
1010
"- loops make computer repeatedly execute some block of code\n",
11+
"- two types of loops: **for** and **while**\n",
12+
" - some keywords that may appear in loops:\n",
1113
" - **for, while, break, continue, in, for ... else, while... else**\n",
1214
" \n",
1315
"### Slice a carrot\n",
@@ -28,12 +30,19 @@
2830
"cell_type": "markdown",
2931
"metadata": {},
3032
"source": [
31-
"## for loop"
33+
"## for loop\n",
34+
"- works with range of values\n",
35+
"- syntax \n",
36+
"```python\n",
37+
"for val in rangeofValues:\n",
38+
" # loop body\n",
39+
"```\n",
40+
"- useful when you know exactly how many times the loop should be executed"
3241
]
3342
},
3443
{
3544
"cell_type": "code",
36-
"execution_count": 8,
45+
"execution_count": 2,
3746
"metadata": {},
3847
"outputs": [
3948
{
@@ -117,6 +126,12 @@
117126
"metadata": {},
118127
"source": [
119128
"## while loop \n",
129+
"- while loop is used when we typically not sure how many times the loop should be executed\n",
130+
"- syntax:\n",
131+
"``` python\n",
132+
"while condition:\n",
133+
" # loop body\n",
134+
"```\n",
120135
"- demonstrate countdown as a script\n",
121136
"- time.sleep(secs)\n",
122137
"- os.system(‘clear’); os.name - 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'\n"

0 commit comments

Comments
 (0)