Introduction
Nested loops help you repeat actions inside other repeated actions, like checking every seat in a theater row by row.
for outerVariable := start; outerVariable < end; outerVariable++ { for innerVariable := start; innerVariable < end; innerVariable++ { // code to repeat } }
for i := 1; i <= 3; i++ { for j := 1; j <= 2; j++ { fmt.Println(i, j) } }
for row := 1; row <= 2; row++ { for col := 1; col <= 3; col++ { fmt.Printf("%d,%d ", row, col) } fmt.Println() }
package main import "fmt" func main() { for i := 1; i <= 3; i++ { for j := 1; j <= 3; j++ { fmt.Printf("%d ", j) } fmt.Println() } }
for i := 0; i < 3; i++ {
for j := 0; j < 2; j++ {
// code
}
}package main
import "fmt"
func main() {
for i := 1; i <= 2; i++ {
for j := 1; j <= 3; j++ {
fmt.Print(i * j, " ")
}
fmt.Println()
}
}for i := 0; i < 3; i++ {
for j := 0; j < 2; j++
fmt.Println(i, j)
}Pass the test and this pattern moves unknown