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" | |
var arr = [10]int{ 1, 21, 35, 4, 30, 6, 12, 9, 4, 10 } | |
func main() { | |
// loop through arr and print out all values | |
for _, v := range arr { | |
fmt.Println(v) |
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" | |
var arr = [10]int{ 1, 21, 35, 4, 30, 6, 12, 9, 4, 10 } | |
func main() { | |
// loop through arr and print out all values | |
for i := 0; i < len(arr); i++ { | |
fmt.Println(arr[i]) |
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() { | |
var x [5]int | |
x[4] = 100 | |
fmt.Println(x) | |
} |
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() { | |
var input float64 | |
fmt.Scanf("%f", &input) | |
switch input { |
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() { | |
i := 1 | |
for i <= 10 { | |
if i % 2 == 0 { | |
fmt.Println(i, "even") | |
} else { |
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() { | |
loops := 1 | |
// while loop | |
for loops < 10 { | |
fmt.Println(loops) |
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" | |
var global1 int // Declaring a variable with `var` keyword | |
var global2 int = 10 // Assigning a value to a variable right away | |
var global3 = "this is ok!" // Go infer type based on your value | |
// bad_var := "this doesn't work" // `:=` can be used only inside a function | |
func main() { |
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() { | |
// Print string in English, Chinese and Thai | |
fmt.Println("Hello Mars!", "你好火星", "สวัสดีดาวอังคาร") | |
} |
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
export GOPATH=$HOME/Go | |
export PATH=$PATH:$GOPATH/bin |
NewerOlder