Loops
Python has just two kinds of loops: while and for loops. While loops check for a logical condition and continue running the loop as long as the condition is true. For loops iterate through any arbitrary sequence, usually a list or a tuple. You’ll need to press control-C to kill this app as there is an infinite (jest) loop at the end.
[code lang=”python”]
#loops
import time
a = 0
while a < 5:
print “decoys”
a += 1
b = [ 99, “salmonella”, 3.14 ]
for item in b:
print item
for i in range(2, 8):
print i
for j in range(4):
print j
for k in range(0, 9, 3):
print k
while True:
print “some day, you will kill me”
time.sleep(1)
[/code]