Python function "repeat ... to <cond. >"

Asked

Viewed 2,216 times

2

I wanted to know if there is the following function, written in pseudocode, in the Python language:

repeat
(commands)

until (condition);

Thank you.

  • Python only has two format loops: while and for each

1 answer

3


You can use a while thus:

contador = 0
while (contador < 9):
   print ('O contador é:', contador)
   contador = contador + 1

That way he checks whether the condition contador < 9 is still valid and executes the inside of the while if true.

Example: https://ideone.com/1q7ruO

If you want to do it in style do/while (do an action and check at the end) you could do so:

contador = 0
while True:
    print ('O contador é:', contador)
    contador = contador + 1
    if not contador < 9:
        break

Example: https://ideone.com/8nJM2f

Browser other questions tagged

You are not signed in. Login or sign up in order to post.