
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to emulate a do-while loop in Python?
Python doesn't have an equivalent of do-while loop as in C/C++ or Java. The essence of do-while loop is that the looping condition is verified at the end of looping body. This feature can be emulated by following Python code −
Example
condition=True x=0 while condition==True: x=x+1 print (x) if x>=5: condition=False
Output
The output is as follows −
1 2 3 4 5
- Related Articles
- How to convert a Python for loop to while loop?
- do…while loop vs. while loop in C/C++
- How to use ‘do while loop’ in Java?
- How to use C# do while loop?
- Do-while loop in Arduino
- Why there is not do...while loop in Python?
- Python - How to convert this while loop to for loop?
- Difference Between while and do-while Loop
- The do…while loop in Javascript
- Java do-while loop example
- Java infinite do-while loop
- What are the differences between while loop and do-while loop in Java?
- How does Python while loop work?
- How do we use continue statement in a while loop in C#?
- How do we use a break statement in while loop in C#?

Advertisements