Skip to content

Instantly share code, notes, and snippets.

@PierreR
Created December 9, 2011 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierreR/1453819 to your computer and use it in GitHub Desktop.
Save PierreR/1453819 to your computer and use it in GitHub Desktop.
Double Loop (updates and pointers)
package main
import "fmt"
type score struct {
points int
}
type frame struct {
scores []score
}
type game struct {
frames [3]frame
}
var f1 = frame{[] score{score{1},score{2}, score{3}}}
var f2 = frame{[] score{score{1},score{2}, score{3}}}
var f3 = frame{[] score{score{1},score{2}, score{3}}}
func (g *game) doIt() {
for i, frame := range g.frames {
for j := range frame.scores {
frame.scores[j].points = 9
}
}
}
func main() {
g := game {[3]frame{f1, f2, f3}}
g.doIt()
fmt.Println(g.frames)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment