Do while loop in Python
In this tutorial, you will learn about the do-while loop in python, its syntax and how to use it in your python
Do while loop in python
Unlike other programming languages, Python doesn’t support the do-while loops. In general, the do-while loop executes the set of codes first and checks the loop condition at the end of the loop. Therefore, we can run a similar program containing the while loop which can be executed at least once.
Program using do-while loop in python
[gamipress_button type=”submit” label=”Run Code Snippet” onclick=”window.open(‘https://coderseditor.com/?id=1331′,’_blank’)”]
i = 57 while True: print(i) i = i + 1 if(i > 60): break
57 58 59 60
Here, we can see that the loop prints the values from 57-60 and then checks for the condition which is i>60, then break. So when the value reaches 60 the condition becomes true and the program exits the loop.