While loop in Python

#The while loop in Python uses a counter variable as a #condition.  The counter is incremented by 1 at the end of #each iteration of the loop and the condition (counter < 5) #is checked at the beginning of each iteration of the loop.
#The while loop will keep looping as long as the condition #(counter < 5) is True.

counter = 0             # <---initialize counter variable
while counter < 5:      # <---check condition if True
    print (counter)
    counter += 1        # <---increment counter by 1

Leave a comment

Design a site like this with WordPress.com
Get started