The Go Blog | Go Documentation | Go wiki | The Go Programming Language (book)
func showHand() []string {
gotcards := make([]string, 0)
for _, i := range "♥♠♣♦" {
for _, j := range "AKQJ098765432" {
gotcards = append(gotcards, string(i)+string(j))
if j == '8' { // I wanna play show-hand
break // break the inner loop
}
}
}
// fmt.Println(gotcards)
return gotcards // finaly i got 28 show-hand cards
}
func topCards(n int) []string {
gotcards := make([]string, 0)
OutterLoop:
for _, i := range "♥♠♣♦" {
for cnt, j := range "AKQJ098765432" {
gotcards = append(gotcards, string(i)+string(j))
if cnt == n-1 { // I wanna play show-hand
break OutterLoop // break the Outter loop using lable
}
}
}
// fmt.Println(gotcards)
return gotcards // finaly i got 28 show-hand cards
}
func playPoker(t string, n int) []string {
if t == "showHand" {
return showHand()
} else if t == "topCards" {
return topCards(n)
} else {
panic("wrong poker game type: showHand or topCards")
}
}
func gBoom(s rune) []string {
boom := make([]string, 0)
for _, i := range "♥♠♣♦" {
second:
for _, j := range "AKQJ098765432" {
fmt.Println(string(i) + string(j))
switch j {
case s:
boom = append(boom, string(i)+string(j))
// single break without label only break the switch not the second for loop
// break only break out to the innermost "for" "switch" "select"
break second
}
}
}
return boom
}
case 1, 3, 7, 7: // compile error two 7 here
case 1, 3, seven(), 7: f1()
func seven() int {
return 7
}
case 1>2: f1()
- case constant string compare to if
- golang/go#10000
stooges := [...]string{"Moe", "Larry", "Curly"}
func Sum(nums ...int) int {
res := 0
for _, n := range nums {
res += n
}
return res
}
primes := []int{2, 3, 5, 7}
fmt.Println(Sum(primes...)) // 17
go test ./...