if else _ golang

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 语句中可以进行变量的初始化

posted on 2015-03-12 13:35  xjk112  阅读(196)  评论(0编辑  收藏  举报