8, iota enumeration

1, the automated producer IOTA constant, each line is automatically incremented by 1

2, iota assigned to the constant use

3, if iota encounter const, will be reset to 0

4, can be written only one iota

5, if it is the same line, the value is the same

// 09_iota enumeration 
Package main 

Import ( 
    " FMT " 
) 

FUNC main () { 
    // . 1, the automated producer IOTA constant, each line, automatically accumulate. 1
     // 2, to constant values used IOTA 
    const ( 
        A = IOTA // 0 
        B = iota // . 1 
        C = iota // . 3 
    ) 
    fmt.Printf ( " A% = D, B = D%, C =% D \ n- " , A, B, C)
     // . 3, if the case iota to const, it will be reset to 0 
    const D = IOTA 
    fmt.Printf ( " D D =% \ n- " , D)
     //4, can write only one IOTA 
    const ( 
        A1 = IOTA // 0 
        B1         // . 1 
        C1         // . 3 
    ) 
    (fmt.Printf " A1 =% D,% = D B1, D C1 =% \ n- " , A1, B1 , C1)
     // . 5, if the same row, the same values are 
    const ( 
        I           = IOTA 
        J1, J2, J3 = IOTA, IOTA, IOTA 
        K           = IOTA 
    ) 
    fmt.Printf ( " I =% D, J1 =% D, % D = J2, J3 =% D, K D =% \ n- " , I, J1, J2, J3, K) 
}

 

Guess you like

Origin www.cnblogs.com/zyqy/p/11241497.html