Home »
Python
Emulate a do-while loop in Python
Python do while loop: Since, python does not support do-while, here we will emulate a do-while loop and will implement similar in Python.
Submitted by Sapna Deraje Radhakrishna, on February 01, 2020
Python as a language doesn't support the do-while loop. However, we can have a workaround to emulate the do-while loop.
The syntax for do-while is as follows,
do {
loop statements;
} while (condition);
Consider the following example implementation of 'do-while' in Java,
public class DoWhile {
public static void main(String[] args) {
int i = 5;
do {
System.out.println("Welcome to Include Help");
i++;
} while (i < 10);
}
}
Output
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
The above example can be emulated in python as follows,
i=5
while True:
print("Welcome to Include Help")
i = i +1
if(i>10):
break
Output
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
Welcome to Include Help
TOP Interview Coding Problems/Challenges