Explaination for a beginner on how does the 'for loop' in python really works when given a condition as well?

32 Views Asked by At

Input:-

for i in range(0,5):
    print (i)
    i=i+2
else:
    print ('none')

output:-

0
1
2
3
4
none

Normally by giving this input, i thought that the output must be something like this:-

0 2 4 none

But instead it also shows numbers 1 and 3. why is it so? why does the loop doesn't stop when it encounters as i=6 and why does it goes again to find new numbers in the range.

I tried asking chatgpt 3.5 and bing ai but none of them were of any help.

0

There are 0 best solutions below