dtm41506 2009-11-12 05:03
浏览 40
已采纳

为什么在这里需要分号?

Here is a test Go program:

package main
import fmt "fmt"
func main () {
    ex := "moo cow
";
    fmt.Print (ex)
}

With the semicolon, it compiles. However, if the semicolon is removed, it doesn't:

string.go:5: syntax error near fmt

Any ideas?


Update (March 2012): Newer Go releases are able to compile both forms (with and without the semicolon).

  • 写回答

2条回答 默认 最新

  • dpndp64206 2009-11-12 05:12
    关注

    From The Go Programming Language Specification:

    Elements of a list of statements are separated by semicolons, which may be omitted only if the previous statement:

    • ends with the closing parenthesis ")" of a list of declarations; or
    • ends with a closing brace "}" that is not part of an expression.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 VB.NET如何绘制倾斜的椭圆