Counting loops in Python when skipping numbers

26 Views Asked by At

How many loops will the following for loop have?

for i in range(1, 5, 2):
     print(i, end=" ")

I know that the output is "1 3", but I'm not exactly certain how it goes through, if it loops for each. My gut wants to say 2 loops.

  1. 1, skip 2

  2. 3, skip 4 and reach end of range.

Is this correct thinking?

0

There are 0 best solutions below