Loops
Cheat sheet · https://pcornel.dk/topic.php?topic=5216
Answer
Loops repeat logic across items or until a condition changes. Safe automation requires bounded iteration, per-item failure visibility, stable collection semantics and an explicit completion condition.
Remember
- Loop complete ≠ every iteration successful; failures can be skipped, swallowed or overwritten by later success.
- Retry loop ≠ resilience automatically; retrying a non-idempotent side effect can duplicate or compound change.
- Parallel loop ≠ faster safely; shared state, rate limits and target dependencies can create races or blast radius.
- Until condition not met ≠ keep waiting forever; timeouts and escalation boundaries are required.
First checks
shellcheck script.sh— flags unsafe loops (SC2013 for-over-cat)while IFS= read -r line; do …; done < file— safe line loopforeach ($i in $list) { … }— PowerShell
Verify in this order
list → loop → per-item action + error handling
Where it usually breaks
Loop termination proves only that iteration control reached an end condition; it does not prove all items succeeded or that repeated actions were side-effect safe.
Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.
Loops scripting boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Input / runtime | Effective inputs, runtime, working context and dependency versions are explicit | Hidden defaults, stale environment, wrong interpreter/path or unvalidated input |
| Logic / execution | Branch/function/module decisions and external actions expose per-operation results | Swallowed failures, shell reinterpretation, blind retries or last-result-wins behavior |
| Result / proof | Exit/exception/log evidence is correlated with independent target read-back | Process success or printed output treated as target success |
| Recovery / troubleshooting | First failed boundary is preserved, changed minimally and retested | Random edits, catch-all suppression or evidence destroyed before diagnosis |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5216