看《Go語言編程》這本書的時候,有這樣一段代碼:編程
for i, v := range server.players { if v.Name == params { i++ if len(server.players) == 1 { server.players = make([]*Player, 0) } elseif i == len(server.players) - 1 { server.players = server.players[:i - 1] } elseif i == 0 { server.players = server.players[1:] } else { server.players = append(server.players[:i - 1], server.players[:i + 1]...) } return nil } }
編譯老是不經過,提示syntax error: unexpected name, expecting semicolon or newline or }app
怎麼看也沒看明白,後來才發現,沒有elseif這個關鍵字。code
else和if之間應該留一個空格。server
就醬。編譯