Advertisement
sissou123

Untitled

Mar 27th, 2022
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. Python Do While – Loop Example
  2. Loops are a set of instructions that run repeatedly until a condition is met. Let's learn more about how loops work in Python.
  3.  
  4. Loops in Python
  5. There are two types of loops built into Python:
  6.  
  7. for loops
  8. while loops
  9. Let's focus on how you can create a while loop in Python and how it works.
  10.  
  11. What is a while loop in Python?
  12. The general syntax of a while loop in Python looks like this:
  13.  
  14. while condition:
  15.     execute this code in the loop's body
  16. 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.
  17.  
  18. A while loop will always first check the condition before running.
  19.  
  20. If the condition evaluates to True then the loop will run the code within the loop's body.
  21.  
  22. For example, this loop runs as long as the number is less than 10:
  23.  
  24. number = 0
  25. while number < 10:
  26.     print(f"Number is {number}!")
  27.     number = number + 1
  28. for more: https://www.clictune.com/eAjB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement