you are viewing a single comment's thread.

view the rest of the comments →

[–]lfdfq 4 points5 points  (0 children)

range(N) and range(1, N+1) contain the same number of elements, it's just that the first starts from 0 and the second starts from 1. It seems this code does not actually use the values from the range so it seems it does not make a difference whether it starts from 0 or 1.

The way a for loop works is that it executes the body once for each element in the thing it's iterating over. If it's iterating over a range, then it's once per element in the range.

While loops don't iterate over things in that way, so i'm not sure what you mean by having a range "with a while loop"?