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
322 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 11, 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 5 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
• 57,700 points
1,590 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
55 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,250 points
1,457 views
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,454 views
0 votes
0 answers
+4 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,800 points
1,085 views
0 votes
1 answer

Increment operators in Python

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

answered May 11, 2018 in Python by Hamartia's Mask
• 1,580 points
307 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
76 views