+ 18
Does python have do-while loop?
15 ответов
+ 11
Thank you
+ 2
A do-while loop is important because it is a post-test loop, meaning that it checks the condition only after executing the code in the loop block. Even though Python doesn't explicitly have the do-while loop , we can emulate it.
+ 2
Python doesn't have a built-in `do-while` loop like some other programming languages, such as C or Java. However, you can achieve similar functionality using a `while` loop in combination with a conditional check at the end. Here's an example:
```python
while True:
# Your code here
# Conditional check for continuation
user_input = input("Do you want to continue? (y/n): ")
if user_input.lower() != 'y':
break
```
In this example, the loop will continue indefinitely (`while True`), and within the loop, you perform your desired operations. After that, you prompt the user if they want to continue. If the user enters 'y', the loop continues; otherwise, it breaks out of the loop.
This construct simulates the behavior of a `do-while` loop where the loop body is executed at least once before checking the condition for continuation.
+ 1
Anurag Madhesia
Python doesn't have do-while loop.
+ 1
No buddy no do while , you can use for loop and while loop for looping in python
0
pannddorra
Really
Can you tell me
0
no do-while-loop, but it exist that.
while (condition) :
instruction 1
instruction 2
...
0
No it does not have that but it has better
0
No
0
No, it doesn't.
0
Yes, and it is called a while loop
0
Yes ofcourse
- 2
*