while loop in python
- A Python ‘while loop’ repeatedly carries out a target statement while the condition is true.
- The loop iterates as long as the defined condition is true. When it ceases to be true and becomes false, control passes to the first line after the loop.
- A loop very similar to for since it also executes a code portion in a repeated way.
- In this case there is no iteration over an object, so this loop doesn’t end when the iteration object is traversed, but when a given condition is not true.
It is very important to take into account that there should be an instruction inside the block to make the while condition false. Otherwise, we could enter into an infinite loop.
>>> while a<40:
a = a+10