00_While Loop Introduction.py

Sign up Free. Don't forget to check out our challenges, lessons, solve and learn series and more ...

Code Snippet

""" Do not forget to indent the statements that are inside the while loop (to be repeated)
They must be repeated to the same level.
Use the Tab key to indent. (space bar can also be used)
When used like this the while loop is said to be 'counter-controlled'.
In this program, x is acting like a counter (going by 1 for each loop round)

x = 1
while x < 5:
    print ('Hi there www.teachyourselfpython.com - I love learning python')
    x = x + 1
print ('done')

Try it yourself