Do-while loop in Python

0 votes
How do we create a do-while loop in Python
May 11, 2018 in Python by kaalabilli
• 1,090 points
1,413 views

2 answers to this question.

0 votes

Python does not have a do-while construct. 

If you wish to emulate a do-while loop, you must make sure that your loop body is execute atleast once, so try this out - 

condition = True
while condition:
    # loop body here
    condition = test_loop_condition()
...
answered May 12, 2018 by Hamartia's Mask
• 1,580 points
0 votes
A more pythonic way would be this:

```

while True:

    # loop body here

    if not condition:

        break

```
answered Jul 6, 2020 by Composer3

Related Questions In Python

0 votes
1 answer

Why there is no do while loop in python

There is no do...while loop because there ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 58,020 points
7,721 views
0 votes
1 answer
0 votes
0 answers

How do you use an else clause in a while loop in python?

Can you give an example? READ MORE

Aug 5, 2019 in Python by Waseem
• 4,540 points
753 views
0 votes
1 answer

Empty while loop in Python

while file.readline().startswith("#"):     pass The pass statement does nothing. It ...READ MORE

answered Dec 5, 2018 in Python by SDeb
• 13,300 points
3,780 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,469 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,128 views
0 votes
1 answer

Increment operators in Python

Python has no unary operators. So use ...READ MORE

answered May 12, 2018 in Python by Hamartia's Mask
• 1,580 points
995 views
0 votes
1 answer

Binary numbers in python

>>> 0b1011 11 READ MORE

answered Jun 6, 2018 in Python by Hamartia's Mask
• 1,580 points
839 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP