om-scogo/skillsh-scraper/go-control-flow
Claude Code and agent skill by om-scogo/skillsh-scraper
- community
Checking that the SKILL.md file is still in the repository.
Use when writing conditionals, loops, or switch statements in Go — including if with initialization, early returns, for loop forms, range, switch, type switches, and blank identifier patterns. Also use when writing a simple if/else or for loop, even if the user doesn't mention guard clauses or variable scoping. Does not cover error flow patterns (see go-error-handling).
Install
npx vskill@latest install om-scogo/skillsh-scraper/go-control-flowSKILL.md
The same SKILL.md was published earlier as om-scogo/skillsh-scraper/go-control-flow.
Go Control Flow
Resource Routing
references/SWITCH-PATTERNS.md- Read when using switch statements, type switches, fallthrough, or labeled breaks.references/BLANK-IDENTIFIER.md- Read when using_, blank imports, unused compile-time assertions, or intentional discards.
If with Initialization
if and switch accept an optional initialization statement. Use it to scope variables to the conditional block:
If you need the variable beyond a few lines after the if, declare it separately and use a standard if instead:
Indent Error Flow (Guard Clauses)
When an if body ends with break, continue, goto, or return, omit the unnecessary else. Keep the success path unindented:
Never bury normal flow inside an else when the if already returns.
Redeclaration and Reassignment
The := short declaration allows redeclaring variables in the same scope:
A variable v may appear in a := declaration even if already declared, provided:
- The declaration is in the same scope as the existing
v - The value is assignable to
v - At least one other variable is newly created by the declaration
Variable Shadowing
Warning: If v is declared in an outer scope, := creates a new variable that shadows it — a common source of bugs:
For Loops
Go's for is its only looping construct, unifying while, do-while, and C-style for:
Range
range iterates over slices, maps, strings, and channels:
Key rules:
- Range over strings yields runes, not bytes —
iis the byte offset - Range over maps has non-deterministic order — don't rely on it
- Use
_to discard the index or value:for _, v := range slice
Parallel Assignment
Go has no comma operator. Use parallel assignment for multiple loop variables:
++ and -- are statements, not expressions — they cannot appear in parallel assignment.
Switch: Labeled Break
break inside a switch within a for loop only breaks the switch. Use a labeled break to exit the enclosing loop:
For type switches, see go-interfaces: Type Switch.
The Blank Identifier
Never discard errors carelessly — a nil dereference panic may follow.
Route compile-time interface assertions to go-interfaces.
Quick Reference
| Pattern | Go Idiom | |
|---|---|---|
| If initialization | if err := f(); err != nil { } | |
| Early return | Omit else when if body returns | |
| Redeclaration | := reassigns if same scope + new var | |
| Shadowing trap | := in inner scope creates new variable | |
| Parallel assignment | i, j = i+1, j-1 | |
| Expression-less switch | switch { case cond: } | |
| Comma cases | case 'a', 'b', 'c': | |
| No fallthrough | Default behavior (explicit fallthrough if needed) | |
| Break from loop in switch | break Label | |
| Discard value | _, err := f() | |
| Side-effect import | import _ "pkg" | |
| Interface check | Route to go-interfaces |
Related Skills
- Error flow: See go-error-handling when structuring guard clauses, early returns, or error-first patterns
- Type switches: See go-interfaces when using type switches, the comma-ok idiom, or interface satisfaction checks
- Nesting reduction: See go-style-core when reducing nesting depth or resolving formatting questions
- Variable scoping: See go-declarations when using if-init,
:=redeclaration, or reducing variable scope
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdata/skills/cxuu-golang-skills/go-control-flow/skills/go-control-flow/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/om-scogo/skillsh-scraper/go-control-flow)