Created
December 9, 2011 23:33
-
-
Save PierreR/1453819 to your computer and use it in GitHub Desktop.
Double Loop (updates and pointers)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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