Skip to content

Commit dc892b3

Browse files
committed
better looping
1 parent b3a0bd6 commit dc892b3

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

loops.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1010
We'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
156156
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:
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
230230
Note that `for thing in stuff:` is not same as `for (thing in stuff):`.
231231
Here the `in` keyword is just a part of the for loop and it has a
232232
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.
243234

244235
Right now the while loop version might seem easier to understand for
245236
you, but later you'll realize that for loops are much easier to work

0 commit comments

Comments
 (0)