Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python Do While – Loop Example
- Loops are a set of instructions that run repeatedly until a condition is met. Let's learn more about how loops work in Python.
- Loops in Python
- There are two types of loops built into Python:
- for loops
- while loops
- Let's focus on how you can create a while loop in Python and how it works.
- What is a while loop in Python?
- The general syntax of a while loop in Python looks like this:
- while condition:
- execute this code in the loop's body
- A while loop will run a piece of code while a condition is True. It will keep executing the desired set of code statements until that condition is no longer true.
- A while loop will always first check the condition before running.
- If the condition evaluates to True then the loop will run the code within the loop's body.
- For example, this loop runs as long as the number is less than 10:
- number = 0
- while number < 10:
- print(f"Number is {number}!")
- number = number + 1
- for more: https://www.clictune.com/eAjB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement