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, I explained about append function algorithm
Now let's see how loop works with append function
Loop over append function
Let's assign the power of 2 to a slice and print it.
With normal loop we can print the slice.
We basicaly loop over the length of the slice using the index.
package main
import "fmt"
var power = []int{1,2,4,8,16,32}
func main() {
for i:=0; i<len(power); i++ {
fmt.Printf("2^%d = %d\n", i, power[i])
}
}
This will output:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
Go inbuilt range function
Go provides a very simple way to loop over a slice.
package main
import "fmt"
var power = []int{1,2,4,8,16,32}
func main() {
for i,v := range power {
fmt.Printf("2^%d = %d\n", i, v)
}
}
Where i is the index and v is the value of the element.
Output:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
we can also define the index as _ if we don't want to use it.
package main
import "fmt"
var power = []int{1,2,4,8,16,32}
func main() {
for _,v := range power {
fmt.Printf("%d\n", v)
}
}
Output:
1
2
4
8
16
32
Conclusion
We understood how to loop over a slice using normal index based loop and range function.
π 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β¦
https://github.com/golang/go/blob/master/src/runtime/slice.go

Top comments (0)