Go 语言 if 语句嵌套
Go 语言教程
· 2019-02-12 22:56:54
你可以在 if 或 else if 语句中嵌入一个或多个 if 或 else if 语句。
语法
Go 编程语言中 if...else 语句的语法如下:
if 布尔表达式 1 {
/* 在布尔表达式 1 为 true 时执行 */
if 布尔表达式 2 {
/* 在布尔表达式 2 为 true 时执行 */
}
}
你可以以同样的方式在 if 语句中嵌套 else if...else 语句
实例
package main
import "fmt"
func main() {
/* 定义局部变量 */
var a int = 100
var b int = 200
/* 判断条件 */
if a == 100 {
/* if 条件语句为 true 执行 */
if b == 200 {
/* if 条件语句为 true 执行 */
fmt.Printf("a 的值为 100 , b 的值为 200\n" );
}
}
fmt.Printf("a 值为 : %d\n", a );
fmt.Printf("b 值为 : %d\n", b );
}
以上代码执行结果为:
a 的值为 100 , b 的值为 200 a 值为 : 100 b 值为 : 200
点击查看所有 Go 语言教程 文章: https://codercto.com/courses/l/13.html
The Everything Store
Brad Stone / Little, Brown and Company / 2013-10-22 / USD 28.00
The definitive story of Amazon.com, one of the most successful companies in the world, and of its driven, brilliant founder, Jeff Bezos. Amazon.com started off delivering books through the mail. Bu......一起来看看 《The Everything Store》 这本书的介绍吧!