Repeat

Do While Loop

Python

 

Do While loop

Python 2.7
count = 5

condition = True
while condition:
    count = count - 1
    print(count)
    condition = (count > 0)

There is no native syntax for do-while loops in Python similar to other Programming Languages like Java.

The difference between do-while and while is in do-while the block is first run and then the condition is checked.

This means that no matter what do-while condition is, the block will always run at least once.

This is one of the ways to mimic Do-While behavior in Python.

This will print 4 3 2 1 0 on Console.