码迷,mamicode.com
首页 > 其他好文 > 详细

后端程序员之路 52、A Tour of Go-2

时间:2017-05-09 13:51:45      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:type   value   nbsp   round   nts   ase   pes   deferred   oat   

# flowcontrol
    - for
        - for i := 0; i < 10; i++ {
        - for ; sum < 1000; {
        - For is Go‘s "while" - for sum < 1000 {
        - Forever - for {
    - if
        - if x < 0 {
        - } else {
        - if v := math.Pow(x, n); v < lim {
    - switch
        - switch os := runtime.GOOS; os {
        - A case body breaks automatically
        - fallthrough
    - defer
        - A defer statement defers the execution of a function until the surrounding function returns.
        - defer fmt.Println("world")
        - Deferred function calls are pushed onto a stack(LIFO)

# moretypes
    - Pointers - var p *int
    - Structs
        - type Vertex struct {
        - v := Vertex{1, 2}
    - Arrays
        - var a [10]int
        - primes := [6]int{2, 3, 5, 7, 11, 13}
    - Slices
        - var s []int = primes[1:4]
        - A slice does not store any data, it just describes a section of an underlying array.
        - q := []int{2, 3, 5, 7, 11, 13}
        - var a [10]int -> a[0:10] == a[:10] == a[0:] == a[:]
        - printSlice fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
        - The zero value of a slice is nil.
        - a := make([]int, 5)  // len(a)=5 || b := make([]int, 0, 5) // len(b)=0, cap(b)=5
        - Slices of slices - board := [][]string{
        - for i, v := range pow { || for i := range pow { || for _, value := range pow {
    - Maps
        - m[key] = elem
        - elem = m[key]
        - delete(m, key)
        - elem, ok = m[key]
    - Function values
        - hypot := func(x, y float64) float64 {
        - return func(x int) int {

后端程序员之路 52、A Tour of Go-2

标签:type   value   nbsp   round   nts   ase   pes   deferred   oat   

原文地址:http://www.cnblogs.com/zapline/p/6829988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!