# File: while.py # Program to show archetypal while loop # # Matt Bishop, MHI 289I, Fall 2020 # import random # just counts from 1 to 10 # the for loop first print("for loop counting from 0 to 4:") for i in range(5): print(i) # now, the same while loop print("while loop counting from 0 to 4:") i = 0 while i < 5: print(i) i += 1 # now an indefinite loop x = True count = 0 while random.randint(0,10) / 3 == 0: print("x =", x, "so loop again") count += 1 print("Looped", count, "times")