|
spudplate
Template scaffolding compiler for spudlang .spud files
|
Runs the body block <int_var> times. The iterator <iter> is bound to the current iteration index (0-based, runs from 0 through <int_var> - 1). Nested repeat, if, ask, and any action statement may appear inside the body.
If num_modules is 3, the loop runs three times, with i taking values 0, 1, 2.
The when clause skips the entire loop if the condition is false:
When use_weekly is false, the loop runs zero times, regardless of num_weeks.
ask is allowed inside a repeat body. Each iteration prompts afresh and binds a fresh value for that iteration. The binding is gone at the start of the next iteration.
Prompts inside repeat are indented two spaces per nesting level. The static (N/M) counter sits next to an iteration K of L indicator, for example (3/7, iteration 2 of 4). Nested loops stack indicators outermost first.
A repeat body introduces a new scope. The iterator and any let or as declared inside the block are local to that body and are not visible after end.
The no-shadowing rule applies: an inner let, as, or repeat iterator cannot reuse a name visible in the surrounding scope. See Scoping for the full rules.
A reassignment inside the body that targets a let from an outer scope mutates the outer binding. This is the way to accumulate a value across iterations.
The accumulator pattern is the only common reason to mutate a let; most templates run cleanly without reassignment.
Each loop has its own scope. The inner iterator day is not visible outside its loop, and cannot shadow week.