Golang用for实现while

Golang没有while关键词,所有用for实现while的功能。

很简单,将for二个;号两边的赋值去掉

for ;; {
}

实例如下

package main

import (
    "time"
)

func main() {

    for ;;{
        print("====\n")
        time.Sleep(1 * 1000 * 1000 *1000)
    }
}

注意:time的Sleep方法中的单位为纳秒。

Published:
2015-07-28 14:10
Category:
Tag: