Package mainimport "FMT" import "OS" Var (A intb INT) func testarrayparmter (ARR [2] INT) {// arr is a copy, so the ARR is changed in the function, println ("") for I: = range arr {arr [I] + = 1 print (ARR [I]) If! (I + 1 = Len (ARR) {print (",")} println ("")} func testsliceparmter (ARR [] INT) {println ("") for I: = range arr {arr [I] + = 1 print (ARR [I]) If! (I + 1 = Len (ARR) {print ("^,")} println ("")} func main () {for I: = 0; I <5; I ++ {for J: = 0; j <= I; j ++ {print ("A")} println ("")} A = 0x77b = 077 const c = "I am const Var" const (D = iotaef = iota) S: = "hello" + "world" ch: = [] Byte (s) // convert s to a byte array ch [0] = 'C' S2: = string ('ssfswerq ') if 1 <2 {if 1> 0 &&! False {FMT. printf ("0 <1 <2 \ n")} else {FMT. printf ("not 0 <1 <2 \ n")} var CC complex128 = 5 + 5ifmt. printf ("d = % d e = % d F = % d S2 = % s cc = % V \ n", d, e, f, S2, CC) FMT. printf ("s = % s A = % d B = % d c = % s \ n", S, A, B, C) file, err: = OS. openfile ("C: \ 2.py", OS. o_rdonly, 0) If Err! = Nil {FMT. println (ERR) return} by: = [] Byte (s) file. read (by) FMT. println (string (by) // read a DD, err: = file. stat () If Err! = Nil {FMT. println (ERR) return} FMT. println (dd) file. close () // use for I: = 1; I <2; I + = 1 {FMT. println (I)} I: = 2 flag: = truehere: // use of goto for I> = 0 {FMT. println (I) I-= 1} For {println ("While true {}") break} if flag {flag = falsegoto here} J: = 0j: for I = 0; I <100; I ++ {for J = 0; j <100; j ++ {if I> 5 {break J // The loop layer where the J tag is located} println (I, j) println ("==== range =") List: = [] string {"A", "B", "C"} for K, V: = range list {println (K, v)} for POs, CHA: = range "ABC" {FMT. printf ("# Pos = % d CHA = '% C' \ n", POs, CHA) // Why does this run to the output before while true {} println ("Switch usage") CCC: = 'A' switch {// If the switch has no expression, it will match true // It will be converted to one matching, known as truecase '0' <= CCC & CCC <= '9': println ('0 ') case 'a'-32 <= CCC & CCC <= 'F'-32: println ('A ') case 'A' <= CCC & CCC <= 'F': // No println ('A')} switch J {Case 1: println ("Case 1 ") case 2: println ("Case 2") Default: println ("case default")} CH = [] Byte ("hhhhhh") CH2: = [] Byte ("hhhhhhh") println (LEN (CH), Len (CH2) for POs: = range ch {// compare string size switch {Case ch [POS]> CH2 [POS]: println ("big") Case ch [POS] <CH2 [POS]: println ("small") }}println ("use of arrays") Arr: = [2] int {1, 2} // both arrays are initialized to 1, 2var arr2 [2] intarr2 = arr // The array is of the same value type: assign an array to another array and copy all elements for I: = range arr2 {print (arr2 [I])} testarrayparmter (ARR) for I: = range arr2 {print (ARR [I])} println ("") arr3: = [...] int {1, 2, 3, 4, 5, 6, 7, 8} println (LEN (arr3) println ("create array") A3: = [3] [2] int {[2] int {1, 2}, [...] int {1, 2}, {3, 4} println (LEN (A3) println ("slice usage --- slice is a pointer to the array header and a reference type, use make to create ") SL: = make ([] int, 10) // create a slicesl with 10 elements saved [1] = 2 println (SL [1]) sl2: = arr3 [2: 4] println (sl2 [0], sl2 [1], Len (sl2), arr3 [: Len (arr3)]) println ("using built-in functions append and copy") SA: = [] int {0, 0} SB: = append (SA, 2, 2) SC: = append (SB, sa ...) // {0, 0, 2, 0, 0} For I: = 0; I <Len (SC); I ++ {// The Goto path to FMT. printf ("= % d =", SC [I])} println ("") var A4 = [8] int {0, 1, 2, 3, 4, 5, 6, 7} var Ss = make ([] int, 6) // the element that copies the most is the minimum length of the two parameter arrays N1: = copy (SS, a4 [0:]) // because the length of S is 6, S = {0, 1, 2, 3, 4, 5} N2: = copy (SS, ss [2:]) // because the replication overlaps, S = {2, 3, 4, 5} println (N1, N2) testsliceparmter (SS) // After the returned Ss = {3, 4, 5, 6, 5, 6} println ("map usage") monthdays: = map [String] int {"Jan": 31, "FEB": 28, "Mar": 31, "APR": 30, "may": 31, "Jun": 30, "Jul": 31, "Aug": 31, "Sep": 30, "Oct ": 31, "Nov": 30, "dec": 31, // note that the last comma cannot be less} println (monthdays ["Nov"]) year: = 0for _, days: = range monthdays {year + = days} monthdays ["ckl_day"] = 31 // Add a new Val to map, OK: = monthdays ["ckl_day"] // checks whether monthdays ["ckl_day"] exists. Save it in OK. // deletes the monthdays ["ckl_day"] item Delete (monthdays, "ckl_day") year2: = 0for _, days: = range monthdays {year2 + = days} val1, ok1: = monthdays ["ckl_day"] println (year, monthdays ["ckl_day"], Val, OK, year2, val1, ok1 )}