Python for
loops are based on iteration, not a condition. They are stopped when StopIteration
is reached, not when a certain Boolean condition evaluates to False
.
range
creates a temporary range object that cannot be changed during iteration. After range(10)
or range(n)
or whatever is called, this object is completely independent of what was used to create it.
You were probably expecting something like this to happen (C code):
for (int i = 0; i < 10; ++i) {
printf("%d ", i);
i = 11;
}
This is not how a for loop works in Python. It is more similar to this:
int range[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int count = 0; count < 10; ++count) {
int i = range[count];
printf("%d ", i);
i = 11;
}