Go 语言 if 语句

Go 语言教程 · 2019-02-12 22:28:27

if 语句由布尔表达式后紧跟一个或多个语句组成。

语法

Go 编程语言中 if 语句的语法如下:

if 布尔表达式 {
   /* 在布尔表达式为 true 时执行 */
}

If 在布尔表达式为 true 时,其后紧跟的语句块执行,如果为 false 则不执行。

流程图如下:

实例

package main

import "fmt"

func main() {
   /* 定义局部变量 */
   var a int = 10
 
   /* 使用 if 语句判断布尔表达式 */
   if a < 20 {
       /* 如果条件为 true 则执行以下语句 */
       fmt.Printf("a 小于 20\n" )
   }
   fmt.Printf("a 的值为 : %d\n", a)
}

以上代码执行结果为:

a 小于 20
a 的值为 : 10

点击查看所有 Go 语言教程 文章: https://www.codercto.com/courses/l/13.html

查看所有标签

Convergence Culture

Convergence Culture

Henry Jenkins / NYU Press / 2006-08-01 / USD 30.00

"Convergence Culture" maps a new territory: where old and new media intersect, where grassroots and corporate media collide, where the power of the media producer, and the power of the consumer intera......一起来看看 《Convergence Culture》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具