Code Monkey home page Code Monkey logo

golang-notes's Introduction

Golang-Notes

The Go Blog | Go Documentation | Go wiki | The Go Programming Language (book)

SheetMusic

Keywords

break

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

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()

chan

const

continue

default

defer

else

fallthrough

for

func

go

goto

if

import

interface

map

package

range

return

select

struct

switch

type

var

Constants

true false

iota

nil

Types

int int8 int16 int32 int64

uint uint8 uint16 uint32 uint64 uintptr

float32 float64 complex128 complex64

bool

byte rune

string

error

Functions

make

len

cap

new

append

copy

close

delete

complex

real

imag

panic

recover

Others

... (ellipsis)

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 ./...

golang-notes's People

Contributors

nocmk2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.