Python Language Loops The "half loop" do-while

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Unlike other languages, Python doesn't have a do-until or a do-while construct (this will allow code to be executed once before the condition is tested). However, you can combine a while True with a break to achieve the same purpose.

a = 10
while True:
    a = a-1
    print(a)
    if a<7:
        break
print('Done.')

This will print:

9
8
7
6
Done.


Got any Python Language Question?