Skip to content

Instantly share code, notes, and snippets.

@yanmhlv
Last active August 29, 2015 14:17
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 yanmhlv/1ee571402f4a83c74676 to your computer and use it in GitHub Desktop.
Save yanmhlv/1ee571402f4a83c74676 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main(){
a := 3
if a == 3 {
fmt.Println("1. if-else, a == 3")
} else {
fmt.Println("1. if-else, a != 3")
}
if a == 10 {
fmt.Println("2. if-else, a == 10")
} else {
fmt.Println("2. if-else, a != 3")
}
if a == 1 {
fmt.Println("3. if-else, result = 1")
} else if a == 2 {
fmt.Println("3. if-else, result = 2")
} else if a == 3 {
fmt.Println("3. if-else, result = 3")
} else {
fmt.Println("3. if-else, result = unknown")
}
switch {
case a == 1:
fmt.Println("4. switch, result = 1")
case a == 2:
fmt.Println("4. switch, result = 2")
case a == 3:
fmt.Println("4. switch, result = 3")
default:
fmt.Println("4. switch, result = unknown")
}
count := 0
for {
fmt.Println("for-while", count)
if count == 3{
break
}
count++
}
count = 0
for count < 3 {
fmt.Println("for-while 2", count)
count++
}
for count=0; count < 3; count++ {
fmt.Println("for-while 3", count)
}
mylist := []int{10, 20, 30}
for index, value := range mylist{
fmt.Println("for-range", index, value, mylist[index])
}
}
package main
import "fmt"
type Account struct {
first_name string
age int
}
func main() {
user := Account{"Ян", 26}
fmt.Println(user)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment