Does the variable used for iteration in a
foreach loop have a more specific term than simply 'the foreach variable?' Especially to differentiate it from the collection variable?
foreach (item in collection)
Edit: Loop variant was suggested (wiki):
In computer science, a loop variant is a mathematical function defined on the state space of a computer program whose value is monotonically decreased with respect to a (strict) well-founded relation by the iteration of a while loop under some invariant conditions, thereby ensuring its termination.
To me this sounds similar to 'iteration variable.' Is this strictly speaking correct? I would have assumed that 'loop variant' refers to the internal integer (or similar) that the
collection enumerator uses for its internal state- not the variable that is set to the
Current value on each iteration.
Also, an enumerator of a linked list or a dummy enumerator that never terminates do not have monotonically decreasing variables, while at the same time the
foreach loop does have its
The motivation of this question is to find a descriptive name for a parameter in a bytecode emitting API. This parameter is a number that refers to the local that will be set on each generated foreach iteration. It's not an
iterationLocal, that would be misleading.
currentLocal may be the most helpful name.