Loop variable
A loop variable is a variable whose value represents, tracks, or controls the current iteration of a loop.
Get Programming: Learn to code with Python
A loop variable is a variable that receives successive items from a sequence during loop execution.
- How it is used
- Deploys loop variables to repeat a for-loop body across numeric sequences or string characters.
- How deep it goes
- Explains assignment and execution step by step, then contrasts automatic for-loop updates with manual while-loop control.
- Examples
- Uses range(3), character printing, string indices, counting exercises, and repeated-book messages as practice.
- What you can do after
- Apply it via Python for loops to process each number in a range or each character in a string.
Read how Get Programming: Learn to code with Python explains loop variable →
Learn Go with Pocket-Sized Projects
A loop variable is a variable whose value identifies or controls the current iteration of a loop.
- How it is used
- Protects values captured by goroutines launched inside loops.
- How deep it goes
- Explains the capture hazard and three protections, but does not develop loop-variable implementation internals.
- Examples
- Uses concurrent maze paths, channel messages, map and slice iteration, and parallel table tests.
- What you can do after
- Diagnose/debug with it by recognizing and preventing incorrect values captured by goroutines in loops.
Read how Learn Go with Pocket-Sized Projects explains loop variable →
Related concepts
- closureused by · A closure is a function or callable value together with access to bindings from the lexical environment in which it was created.
- loopused by · A loop is a programming control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- bindingkind of · Name binding is the association of an identifier with the program entity or value it denotes.
- lambdaaddressed by · A lambda is a language construct that defines an unnamed function or callable, often as a value.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

