【问题标题】:Iteration again and again using loop使用循环一次又一次地迭代
【发布时间】:2021-05-22 10:42:07
【问题描述】:

我想循环一次又一次地迭代, 就像你从 0 到 4 一样。 达到 4 后,它又从 0 开始。 有可能吗?

while True:
   while I <10:
       if I <=5:
        for c in a:
         run.chat(i)
         i+=1
       else:
           continue

是真的代码吗?

【问题讨论】:

    标签: loops for-loop foreach while-loop nested-for-loop


    【解决方案1】:

    当然,只要变量到达边界就重置它:

    i = 0
    while True:
        print(i)
        i += 1
        if (i > 4):
            i = 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-12
      • 2016-03-14
      • 2014-10-11
      • 2015-03-23
      • 2010-12-28
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多