【问题标题】:how to emulate the do while statement in python? [duplicate]如何模拟python中的do while语句? [复制]
【发布时间】:2020-08-28 10:46:53
【问题描述】:

问题如下:编写一个程序,在屏幕上写 1 到 100、1 中 1、3 次。第一次应该用for,第二次用while,第三次用dowhile,怎么模拟dowhile语句。 就我所做的那样遵循代码:

i = 0
n = 0
for n in range(100):
 print(n - 1)
 while i < 100:
  print(i)
  i = i + 1

【问题讨论】:

  • python没有do while循环,
  • obrigado pela resposta.

标签: python loops while-loop pycharm


【解决方案1】:

Python没有do while循环,你可以这样模拟

i = 1  

while True:  
    print(i)  
    i = i + 1  
    if(i > 100):  
        break  

【讨论】:

  • 感谢您提供解决我问题的替代方法
猜你喜欢
  • 2020-05-07
  • 1970-01-01
  • 2016-01-10
  • 2010-10-19
  • 2016-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多