skip to content
Alvin Lucillo

Iterate over integer literal

/ 1 min read

This for…range loop allows you to iterate depending on the literal value. The syntax is much simpler than the classic format. It’s used when the number of iterations are fixed/pre-determined. One example usage is for test mock calls.

func main() {
	for range 4 {
		fmt.Println("Como vai")
	}
}