You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/02-loop.md
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,8 +156,16 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
156
156
157
157
158
158
> ## What's in a name?
159
-
> In the example above, the loop variable was given the name `char` as a mnemonic; it is short for 'character'. 'Char' is not a keyword in Python that pulls the characters from words or strings. In fact when a similar loop is run over a list rather than a word, the output would be each member of that list printed in order, rather than the characters.
160
-
> ~~~
159
+
>
160
+
> In the example above, the loop variable was given the name `char`
161
+
> as a mnemonic; it is short for 'character'.
162
+
> 'Char' is not a keyword in Python that pulls the characters
163
+
> from words or strings.
164
+
> In fact when a similar loop is run over a list rather than a word,
165
+
> the output would be each member of that list printed in order,
166
+
> rather than the characters.
167
+
>
168
+
> ~~~
161
169
> list = ['oxygen','nitrogen','argon']
162
170
> for char in list:
163
171
> print(char)
@@ -170,13 +178,18 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
170
178
> argon
171
179
> ~~~
172
180
> {: .output}
173
-
> We can choose any name we want for variables. We might just as easily have chosen the name `banana` for the loop variable, as long as we use the same name when we invoke the variable inside the loop:
181
+
>
182
+
> We can choose any name we want for variables.
183
+
> We might just as easily have chosen the name `banana`
184
+
> for the loop variable,
185
+
> as long as we use the same name when we invoke the variable inside the loop:
186
+
>
174
187
> ~~~
175
188
> word = 'oxygen'
176
189
> for banana in word:
177
190
> print(banana)
178
191
> ~~~
179
-
> {.python}
192
+
> {: .python}
180
193
>
181
194
> ~~~
182
195
> o
@@ -187,7 +200,10 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
187
200
> n
188
201
> ~~~
189
202
> {: .output}
190
-
> It is a good idea to choose variable names that are meaningful, otherwise it would be more difficult to understand what the loop is doing.
203
+
>
204
+
> It is a good idea to choose variable names
205
+
> that are meaningful so that it is easier
206
+
> to understand what the loop is doing.
191
207
{: .callout}
192
208
193
209
Here's another loop that repeatedly updates a variable:
0 commit comments