@@ -5,7 +5,7 @@ There are different kinds of loops:
55
66- [ While loops] ( #while-loops ) repeat something while a condition is true.
77- [ 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 .
99
1010We'll talk about all of these in this tutorial.
1111
@@ -149,8 +149,8 @@ print("It's raining!")
149149
150150## For loops
151151
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:
154154
155155``` py
156156stuff = [' 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:
178178
179179``` py
180180>> > 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
182182>> > index = 0
183183>> > while index < length_of_stuff:
184184... print (stuff[index])
@@ -230,16 +230,7 @@ how about you
230230Note that ` for thing in stuff: ` is not same as ` for (thing in stuff): ` .
231231Here the ` in ` keyword is just a part of the for loop and it has a
232232different 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.
243234
244235Right now the while loop version might seem easier to understand for
245236you, but later you'll realize that for loops are much easier to work
0 commit comments