【问题标题】:Is there a specific way of creating a REPEAT_UNTIL loop in python? [duplicate]是否有在 python 中创建 REPEAT_UNTIL 循环的特定方法? [复制]
【发布时间】:2014-07-26 07:38:04
【问题描述】:

我得到了伪代码:

REPEAT
    READ mark
UNTIL mark <= 100 and mark >= 0

然后继续执行各种 IF 循环。

我需要在 Python 中重构这段代码,特别是使用 REPEAT-UNTIL 循环。我知道如何使用 FOR 或 WHILE 循环来实现这一点,但我之前没有在 python 中遇到 REPEAT-UNTIL。这可能吗?

提前致谢。

编辑:这是一道考试题。如果我使用 Python 并使用 while 循环而不是使用具有 REPEAT-UNTIL 循环的其他语言,我会失去分数吗?

【问题讨论】:

  • 除了forwhile,Python 中没有其他循环结构。

标签: python loops pseudocode


【解决方案1】:

没有像你描述的那样的循环,但我经常诉诸于:

while True:
     if condition:
         break
     do_stuff()  #this line may not ever be reached

或:

while True:
     do_stuff()      # this line gets executed at least once
     if condition:
         break

【讨论】:

    猜你喜欢
    • 2022-01-21
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 2020-01-14
    相关资源
    最近更新 更多