Python code behaving differently on replacing 'while' loop by 'for' loop

python3

#1

I am just starting out with Python and was solving one of the problems from July challenges. I have solved the problem in C++ and translated that code to Python, however on submitting I observed that using while loop instead of for loop to iterate over the various test cases results in different outcomes.

Here is what I am doing:

results in RTE (NZEC)

t = int(input())

while t:
    # solve
    t -= 1

using for loop

Results in AC

t = int(input())

for _ in range(t)
    # solve

I am using Python 3 and while submitting I have selected python3 compiler as well.


#2

If you use for loop, the range of variable is 0,1,…,t-1
If you use while loop as in your code, the range of variable is t,t-1,…,2,1.
They are different ranges.