Files
oh-my-pi/packages/coding-agent/src/discovery/builtin-rules/go-range-int.md
T
can1357 c101452bb5 refactor: restructured and condensed agent prompts and system instructions
- Refactored and condensed numerous system prompts, agent instructions, and tool documentation files across packages.
- Streamlined workflow rules, formatting constraints, and execution guidelines for improved clarity and brevity.
- Updated discovery rules, recommendation criteria, and syntax standards in prompt templates.
2026-08-12 01:48:14 +02:00

928 B

description, interruptMode, scope, astCondition
description interruptMode scope astCondition
Use for i := range n instead of the C-style for i := 0; i < n; i++ loop (Go 1.22) never tool:edit(*.go), tool:write(*.go)
for $I := 0; $I < $N; $I++ { $$$BODY }

Go 1.22: for ranges integers. For i := 0; i < n; i++, prefer for i := range n; if index unused, for range n.

Avoid

for i := 0; i < n; i++ {
	use(i)
}

for i := 0; i < len(s); i++ {
	use(s[i])
}

Use

for i := range n {
	use(i)
}

// Ranging the slice directly is usually clearer than indexing.
for i := range s {
	use(s[i])
}

// Index unused → drop it entirely.
for range n {
	tick()
}

Exceptions

  • Keep explicit: non-zero start; step other than ++; descending (for i := n - 1; i >= 0; i--).
  • Keep explicit if body reassigns loop variable or depends on i surviving past loop.
  • Requires Go 1.22+. If module go directive older, keep classic loop.