This file contains hidden or 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" | |
func main() { | |
for i:=1; i<=50; i++ { | |
if i % 2 == 0 { | |
fmt.Println("even") | |
} else if i % 3 == 0 { | |
fmt.Println("odd") |
This file contains hidden or 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" | |
func main() { | |
for i:=0; i<=5; i++ { | |
switch i { | |
case 0: fmt.Println("Zero") | |
case 1: fmt.Println("One") | |
case 2: fmt.Println("Two") |
This file contains hidden or 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" | |
func main(){ | |
x:=make(map[string]int) | |
x["key"] = 10 | |
fmt.Println(x["key"]) | |
} |
This file contains hidden or 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" | |
func main() { | |
elements:= make(map[string]string) | |
elements["H"] = "Hydrogen" | |
elements["He"] = "Helium" | |
elements["Li"] = "Lithium" | |
elements["Be"] = "Beryllium" |
This file contains hidden or 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" | |
func main() { | |
elements:= map[string]string { | |
// shorter way of listing key pairs | |
"H":"Hydrogen", | |
"He":"Helium", | |
"Li":"Lithium", |
This file contains hidden or 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" | |
func main() { | |
// a map of other maps | |
elements:= map[string]map[string]string { | |
"H":map[string]string { | |
"name":"Hydrogen", |
This file contains hidden or 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" | |
func main() { | |
x:= []int { | |
48,96,86,68, | |
57,82,63,70, | |
37,34,83,27, | |
19,97,9,17, |
This file contains hidden or 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" | |
func average(xs[]float64)float64 { | |
total:=0.0 | |
for _,v:=range xs { | |
total +=v | |
} | |
return total/float64(len(xs)) |
This file contains hidden or 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" | |
func f(x int) { | |
fmt.Println(x) | |
} | |
func main() { | |
x:=5 |
This file contains hidden or 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" | |
func f2() int { | |
return 1 | |
} | |
func f1() int { | |
return f2() | |
} |