码迷,mamicode.com
首页 > 其他好文 > 详细

if else _ golang

时间:2015-03-12 14:50:46      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

if else 在 golang

package main

import (
    "fmt"
)

func main() {

    if 7%2 == 0 {
        fmt.Println("7 is even")
    } else {
        fmt.Println("7 is odd")
    }

    if 8%4 == 0 {
        fmt.Println("8 is divisible by 4")
    }

    if num := 9; num < 0 {
        fmt.Println(num, "is negative")
    } else if num < 10 {
        fmt.Println(num, "has 1 digit")
    } else {
        fmt.Println(num, "has multiple digits")
    }
}
7 is odd
8 is divisible by 4
9 has 1 digit

 总结 :

   1 : 在 if 语句中可以进行变量的初始化

if else _ golang

标签:

原文地址:http://www.cnblogs.com/jackkiexu/p/4332153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!