Last number of Range Theory for For Loops
for i in range(n,0,-1):
It runs from n to 1.
Because what I think is that the third argument of the for is by default 1 and if we pass something then it take that as an argument
So, what I think is that the formula for last element of the loop is:
lastElement = lastNumber - lastArgument
for i in range(n):
In this first number is by default 0 and last number is
lastElement = n - 1(By default it is 1)
For reverse loops:
lastElement = n - (-1)
= n + 1
So for above Straight Loop:
Iterator will move from 1 to n-1
and for Reverse Loop:
Iterator will move from n to 1
Comments
Post a Comment