Python as a language doesn't support the do-while loop. However, we can have a workaround to emulate the do-while loop.
Python作为一种语言不支持do-while循环。 但是,我们可以采用一种变通方法来模拟do-while循环 。
The syntax for do-while is as follows,
do-while的语法如下,
do {
loop statements;
} while (condition);
Consider the following example implementation of 'do-while' in Java,
考虑以下Java中“ do-while”的示例实现,
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,
上面的示例可以在python中模拟如下,
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
翻译自: https://www.includehelp.com/python/emulate-a-do-while-loop-in-python.aspx