Akmaral
asked

Expert
Abhay Jajodia answered
Hello Akmaral, really nice question.
When you write a countdown loop, you need a condition that tells Python exactly when to stop. Using i > 0 does that perfectly. As long as i is still greater than zero, the loop keeps running. The moment i hits zero, the condition becomes false, and the loop stops.
So if you start at 5 and subtract 1 each time:
i = 5
while i > 0:
print(i)
i = i - 1
youâll get:
5
4
3
2
1
The loop ends right before it would go into negative numbers. Itâs simply a clean and safe stopping point.
If you have further questions, I'm here to help.
C++
This question was asked as part of the Learn C++ Basics course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
