While loop Beginner Question 2


Don` t get how it works like.Please,explain somebody,so the kettle would get it

We have the variable i = 5.

While will loop, and in every loop it will print i, then i-1.
There is a condition inside While, if that condition is meet then the loop is going to break (stop).

This is the loop, step by step.
print (i) 5, then i becomes 4. Is i <= than 2 ? No.
print (i) 4, then i becomes 3. Is i <= than 2 ? No.
print (i) 3, then i becomes 2. Is i <= than 2 ? Yes. Then break (stop the loop)

1 Like