Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
The for loop
The while loop
Nested loops
break and continue
16. break with while loops


Great! So far, our while loops only ended when the loop condition was satisfied. However, we can also decide to end a loop inside it:

user_input = input('Please provide a number: ')
while True:
  if user_input.isnumeric():
  user_input = input('Not a number! Please provide a number: ')
print('Your number is:', user_input)

while True is used to introduce an infinite loop – the condition True is always true. However, inside the loop, we provided the following if statement:

if user_input.isnumeric(): 

The break keyword is used to terminate the whole loop. Once the user provides a real number, the loop immediately finishes.


Keep asking the user to write the year in which Python was first released: 'In which year was Python first released? '

When the answer is finally correct (1990), print: Correct!

Use a break statement.

Stuck? Here's a hint!

Remember to use int() to convert from string to int.