Python short course: Break from while loop in Python

 The 'break' can be used to jump out in the loop body. For example:



In [1]: while True:
   ...:     line = input('> ')
   ...:     if line=='done':
   ...:         break
   ...:     print(line)
   ...: print('Done')
> Hello Python!
Hello Python!
> done
Done

Reference: 
Allen B. Downey. Think Python (2nd ed.) O'Reilly, 2016

Comments

Popular posts from this blog

Research from the Lab's Little AI Scholars: Learn the life language using artificial intelligence

Lab's recommendation: Awesome books to learn machine learning and AI (continue updating)

Lab's weekly topic - week 49, 2023 - What's limitations and possible solutions for a new AI tools to detect blood poisoning?