Search code examples
pythonloopspseudocode

Is there a specific way of creating a REPEAT_UNTIL loop in python?


I've been given the pseudo-code:

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

It then continues on with various IF loops.

I need to reconstruct this code in Python, specifically using a REPEAT-UNTIL loop. I know how I can achieve this with a FOR or WHILE loop, but I haven't come across REPEAT-UNTIL in python before. Is this possible?

Thanks in advance.

Edit: this is an exam question. Would I lose marks if I use Python and use a while loop rather than using a different language that has REPEAT-UNTIL loops?


Solution

  • There isn't a loop like what you describe but I often resort to things like:

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

    or:

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