Hello, I'm Ganesh Kumar. I'm working on git-lrc: a Git hook for Checking AI generated code.
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
In my previous post, we have learned about data types in Go.
Now, we will learn about loops and control flow in Go.
Loops
In Go, loops are used to execute a block of code repeatedly until a specific condition is met.
Unlike other languages that have while or do-while loops, Go keeps it simple: for is the only looping construct available.
The Three-Component Loop
The most common form of a loop includes an init statement, a condition expression, and a post statement.
package main
import "fmt"
func main() {
sum := 0
// i := 0 (initialization); i < 10 (condition); i++ (post statement)
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println("The sum is:", sum)
}
Key Fixes:
-
Variable Declaration: In your snippet,
iwas not declared. In Go, you must usei := 0or declare it beforehand. -
Typo: You had
sum += l(lowercase L) instead ofsum += i. -
Formatting:
fmt.Printfrequires a format string; for simple values,fmt.Printlnis usually easier.
Conditional Control Flow
Conditional statements allow your program to make decisions based on specific criteria. Go supports the standard if, else if, and else blocks.
The if Statement
Goβs if statements are straightforward. One unique feature is that you don't need parentheses () around the condition, but braces {} are mandatory.
package main
import "fmt"
func main() {
var temp = 20
if temp > 30 {
fmt.Println("Hot")
} else if temp > 20 {
fmt.Println("Warm")
} else {
// Since temp is 20, it doesn't meet the >20 condition
fmt.Println("Cold")
}
}
Output:
gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go
Cold
Conclusion
Control flow is the backbone of logic in Go.
By mastering the for loop and conditional if statements, you can handle almost any iterative or decision-making task in your applications.
Go's design encourages clean, readable code by limiting the number of ways you can perform these operations.
π Check out: git-lrc
Any feedback or contributors are welcome! Itβs online, open-source, and ready for anyone to use.
β Star it on GitHub:
HexmosTech
/
git-lrc
Free, Unlimited AI Code Reviews That Run on Commit
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
See It In Action
See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements
git-lrc-intro-60s.mp4
Why
- π€ AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
- π Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
- π Build a habit, ship better code. Regular review β fewer bugs β more robust code β better results in your team.
- π Why git? Git is universal. Every editor, every IDE, every AIβ¦

Top comments (0)