In this example
for (int i = 0; i < max; i++) {}
The i is used to help determine when a loop should end/stop iteration.
Python does this automagically, behind the scenes for you.
The variable i in this example:
for i in ('a', 'b', 'c'):
is a placeholder to hold the values that are being iterated over.
It is customary for the i variable to be called by names such as:
- target variable
- iteration variable
Behind the scenes, when the for loop runs out of items to iterate over, a StopIteration condition is raised and the for loop will exit.
The documentation references this:
for_stmt ::= “for” target_list “in” expression_list “:” suite
[“else” “:” suite]
The expression list is evaluated once; it should yield an iterable
object. An iterator is created for the result of the expression_list.
The suite is then executed once for each item provided by the
iterator, in the order returned by the iterator. Each item in turn is
assigned to the target list using the standard rules for
assignments (see Assignment statements), and then the suite is
executed. When the items are exhausted (which is immediately when the
sequence is empty or an iterator raises a StopIteration exception),
the suite in the else clause, if present, is executed, and the loop
terminates.
NOTE: target_list does NOT mean the item is an actual list.