How to Decrement a Loop in Python
If you need to decrement a loop in Python, then you can do the following:
How to Decrement a loop in Python using -1
The optional third argument you can pass to the range
function is the order.
The default order is to count up / increment, while the -1
value, is to count down / decrement.
Output: 3 2 1
How to Decrement a loop in Python using while
You can also use a while
loop and set the value to the upper bound, and then decrement while in the loop itself.
Output: 3 2 1