Created
May 17, 2013 16:18
-
-
Save bootandy/5600200 to your computer and use it in GitHub Desktop.
go notes
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
Note return type on end of function: | |
func add(x int, y int) int { | |
return x + y | |
} | |
Can be shortened to: | |
func add(x, y int) int { | |
return x + y | |
} | |
Can return tuples: | |
func swap(x, y string) (string, string) { | |
return y, x | |
} | |
Works out which vars to return by naming: | |
func split(sum int) (x, y int) { | |
x = sum * 4 / 9 | |
y = sum - x | |
return | |
} | |
Constants: | |
const Pi = 3.14 | |
For loop. No () allowed. {} required (horay). [also with if] | |
sum := 1 | |
for i := 0; i < 10; i++ { | |
sum += i | |
} | |
For is also While | |
sum := 1 | |
for sum < 1000 { | |
sum += sum | |
} | |
fmt.Println(sum) | |
Variable scope bound by {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment