块
少于1分钟
Blocks 块
A block is a possibly empty sequence of declarations and statements within matching brace brackets.
块是一对匹配的花括号内可能为空的声明和语句序列。
Block = "{" StatementList "}" .
StatementList = { Statement ";" } .
In addition to explicit blocks in the source code, there are implicit blocks:
源代码中除了显式块之外,还有隐式块:
- The universe block encompasses all Go source text.
- 包含所有的Go源码文本的
universe block
。 - Each package has a package block containing all Go source text for that package.
- 每个包都有一个
package block
,包含该包的所有 Go 源代码。 - Each file has a file block containing all Go source text in that file.
- 每个文件都有一个
file block
,包含该文件中的所有Go 源代码。 - Each “if”, “for”, and “switch” statement is considered to be in its own implicit block.
- 每个 “if"、"for “和 “switch “语句都被认为是在自己的隐式块中。
- Each clause in a “switch” or “select” statement acts as an implicit block.
- “switch“或 “select “语句中的每个子句都是一个隐式块。
Blocks nest and influence scoping.
块是可以嵌套并影响着作用域。