@@ -133,6 +133,29 @@ immediately.
133133>> >
134134```
135135
136+ While with a condition
137+
138+ ``` python
139+ >> > cont = 10
140+ >> > while (cont >= 0 ):
141+ ... print (cont)
142+ ... cont -= 1
143+ ...
144+ 10
145+ 9
146+ 8
147+ 7
148+ 6
149+ 5
150+ 4
151+ 3
152+ 2
153+ 1
154+ 0
155+ >> >
156+ ```
157+
158+
136159## Until loops
137160
138161Python doesn't have until loops. If we need an until loop, we can use
@@ -212,6 +235,7 @@ how about you
212235>> >
213236```
214237
238+
215239Without the comments, that's only two simple lines, and one variable.
216240Much better than anything else we tried before.
217241
@@ -232,6 +256,7 @@ Here the `in` keyword is just a part of the for loop and it has a
232256different meaning than it would have if we had ` thing in stuff ` without
233257a ` for ` . Trying to do ` for (thing in stuff): ` creates an error.
234258
259+
235260Right now the while loop version might seem easier to understand for
236261you, but later you'll realize that for loops are much easier to work
237262with than while loops and index variables, especially in large projects.
260285>> >
261286```
262287
288+ You can print the multiplication tables.
289+
290+ ``` python
291+ >> > table = 2
292+ >> > for i in range (1 , 11 ):
293+ ... print (table," x" , i, " =" ,(table* i))
294+ ...
295+ 2 x 1 = 2
296+ 2 x 2 = 4
297+ 2 x 3 = 6
298+ 2 x 4 = 8
299+ 2 x 5 = 10
300+ 2 x 6 = 12
301+ 2 x 7 = 14
302+ 2 x 8 = 16
303+ 2 x 9 = 18
304+ 2 x 10 = 20
305+ >> >
306+ ```
307+
263308If we can for loop over something, then that something is ** iterable** .
264309Lists, tuples and strings are all iterable.
265310
311+
266312There's only one big limitation with for looping over lists. We
267313shouldn't modify the list in the for loop. If we do, the results can
268314be surprising:
0 commit comments