@@ -5,7 +5,7 @@ There are different kinds of loops:
5
5
6
6
- [ While loops] ( #while-loops ) repeat something while a condition is true.
7
7
- [ Until loops] ( #until-loops ) repeat something while a condition is false.
8
- - [ For loops] ( #for-loops ) repeat something for each element of a list .
8
+ - [ For loops] ( #for-loops ) repeat something for each element of something .
9
9
10
10
We'll talk about all of these in this tutorial.
11
11
@@ -149,8 +149,8 @@ print("It's raining!")
149
149
150
150
## For loops
151
151
152
- Let's say we have a list of things we want to print. To print each item
153
- in stuff , we could just do a bunch of prints:
152
+ Let's say we have [ a list] ( lists-and-tuples.md ) of things we want to
153
+ print. To print each item in it , we could just do a bunch of prints:
154
154
155
155
``` py
156
156
stuff = [' hello' , ' hi' , ' how are you doing' , ' im fine' , ' how about you' ]
@@ -178,7 +178,7 @@ We could also create an index variable, and use a while loop:
178
178
179
179
``` py
180
180
>> > stuff = [' hello' , ' hi' , ' how are you doing' , ' im fine' , ' how about you' ]
181
- >> > length_of_stuff = len (stuff) # len(stuff) is 5
181
+ >> > length_of_stuff = len (stuff) # len is short for length, len (stuff) is 5
182
182
>> > index = 0
183
183
>> > while index < length_of_stuff:
184
184
... print (stuff[index])
@@ -230,16 +230,7 @@ how about you
230
230
Note that ` for thing in stuff: ` is not same as ` for (thing in stuff): ` .
231
231
Here the ` in ` keyword is just a part of the for loop and it has a
232
232
different meaning than it would have if we had ` thing in stuff ` without
233
- a ` for ` . Trying to do ` for (thing in stuff): ` creates an error:
234
-
235
- ``` py
236
- >> > for (thing in stuff):
237
- File " <stdin>" , line 1
238
- for (thing in stuff):
239
- ^
240
- SyntaxError : invalid syntax
241
- >> >
242
- ```
233
+ a ` for ` . Trying to do ` for (thing in stuff): ` creates an error.
243
234
244
235
Right now the while loop version might seem easier to understand for
245
236
you, but later you'll realize that for loops are much easier to work
0 commit comments