为什么在这里需要分号? [英] Why do I need a semicolon here?

查看:69
本文介绍了为什么在这里需要分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个测试Go程序:

Here is a test Go program:

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

使用分号进行编译.但是,如果删除了分号,则不会:

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


string.go:5: syntax error near fmt

有什么想法吗?

更新(2012年3月):较新的Go版本可以编译两种形式(带和不带分号).

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

推荐答案

来自 Go编程语言规范:

语句列表的元素是用分号分隔,可能是仅在前一个声明:

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

  • 以声明列表的右括号)"结尾;或
  • 以不包含在表达式中的大括号}"结尾.

这篇关于为什么在这里需要分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆