While Loops
March 5, 2018
while loops are a good deal more difficult as you have to visualise what is actually happening. One condition will keep running potentially forever until that condition is no longer met. The script below appends numbers to a list and stops doing so when the value is equal to or greater than 6.
i = 0
numbers = []
while i < 7:
print "The number at the top is now: %d" % i
numbers.append(i)
i = i + 1
print "Numbers are now", numbers
print "The number at the bottom is now: %d" % i
print "The numbers:"
for num in numbers:
print num
Recent Entries
- NSA Got Mythos Anyway April 20, 2026
- Seventy Thousand Hours of Stalemate April 20, 2026
- Ginny Danbury, 1989 April 19, 2026