"repeat ... even cond." function in Python

2

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

repeat
(commands)

to (condition);

Thank you.

    
asked by anonymous 25.03.2017 / 16:28

1 answer

3

You can use while like this:

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

In this way it checks to see if the contador < 9 condition is still valid and runs inside the while if it is true.

Example: link

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

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

Example: link

    
25.03.2017 / 16:30