+ 18

Does python have do-while loop?

14th Apr 2021, 8:22 PM
Anurag Madhesia
Anurag Madhesia - avatar
13 Answers
+ 11
Thank you
15th Apr 2021, 10:14 AM
Anurag Madhesia
Anurag Madhesia - avatar
+ 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.
16th Apr 2021, 5:15 PM
SoloLearner
+ 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.
8th Jan 2024, 2:31 AM
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫 - avatar
+ 1
Anurag Madhesia Python doesn't have do-while loop.
15th Apr 2021, 11:30 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 1
No buddy no do while , you can use for loop and while loop for looping in python
10th Aug 2022, 12:29 PM
Swaraj Soubhagya Khandai
Swaraj Soubhagya Khandai - avatar
0
pannddorra Really Can you tell me
16th Apr 2021, 7:50 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
no do-while-loop, but it exist that. while (condition) : instruction 1 instruction 2 ...
14th Jul 2021, 8:59 PM
Ali Lahreche
0
No it does not have that but it has better
4th May 2022, 7:12 AM
Chris Jonathan
Chris Jonathan - avatar
0
No
26th May 2022, 11:51 AM
Hrithika Reddy
Hrithika Reddy - avatar
0
No, it doesn't.
4th Jun 2022, 8:29 AM
Hrithika Reddy
Hrithika Reddy - avatar
0
Yes, and it is called a while loop
5th Mar 2023, 7:37 PM
Welcome To Dodgeball
Welcome To Dodgeball - avatar
0
Yes ofcourse
11th Sep 2024, 5:57 AM
Deepika Singh
Deepika Singh - avatar
- 2
*
8th May 2021, 7:03 AM
AntCos
AntCos - avatar