地鼠每次选好了一块地,打洞,坚持半个月发现地下有块石头,然后他就想绕路了。。。殊不知绕路只会让它离成果越来越远

package main

import (
"fmt"
"math/rand"
"time"
) func testFor1() {
var i int
for i = ; i < ; i++ {
fmt.Printf("i=%d\n", i)
}
fmt.Printf("final:i=%d\n", i)
} func testFor2() {
var i int
for i = ; i < ; i++ {
fmt.Printf("i=%d\n", i)
if i > {
break
}
}
fmt.Println(i)
} //打印奇数
func testFor3() {
var i int
for i = ; i < ; i++ {
//正整数,就调出本次循环,所以不打印
if i% == {
continue
}
fmt.Printf("i=%d\n", i)
} }
func testFor4() {
i :=
for i <= {
fmt.Printf("i=%d\n", i)
i = i +
}
} func testFor5() {
i :=
for i <= {
fmt.Printf("i=%d\n", i)
i = i +
}
} func testMultiSign() {
a, b, c := , "hello",
fmt.Printf("a=%d b=%s c=%d\n", a, b, c)
} func testFor6() {
for no, i := , ; i <= && no <= ; i, no = i+, no+ {
fmt.Printf("%d*%d=%d\n", no, i, no*i)
}
} func testFor7() {
for {
fmt.Printf("hello\n")
time.Sleep(time.Second)
}
} //峰云大神-http://xiaorui.cc/2016/03/23/golang%E9%9A%8F%E6%9C%BAtime-sleep%E7%9A%84duration%E9%97%AE%E9%A2%98/
func fengyun() {
rand.Seed(time.Now().UnixNano())
for i := ; i < ; i++ {
x := rand.Intn()
fmt.Println(x)
time.Sleep(time.Duration(x) * time.Second)
}
} //入口执行函数
func main() {
//testFor1()
//testFor2()
//testFor3()
//testFor4()
//testFor5()
//testFor6()
//testFor7()
fengyun()
}

Golang之(for)用法的更多相关文章

  1. golang 常量的用法

    1.Golang常量的用法 //常量的用法 var num int num =9 //1.常量声明的时候必须赋值 const tax int = 0 //2.常量值是无法修改的 //tax = 10 ...

  2. golang包time用法详解

    在我们编程过程中,经常会用到与时间相关的各种务需求,下面来介绍 golang 中有关时间的一些基本用法,我们从 time 的几种 type 来开始介绍. 时间可分为时间点与时间段,golang 也不例 ...

  3. golang(11) 反射用法详解

    原文链接:http://www.limerence2017.com/2019/10/14/golang16/ 反射是什么 反射其实就是通过变量动态获取其值和类型的一种技术,有些语言是支持反射的比如py ...

  4. golang flag简单用法

    package main import ( "flag" "strings" "os" "fmt" ) var ARGS ...

  5. Golang之waitgroup用法

    我敲下一堆代码,终于长出了果实,今天是个伟大日子 package main import ( "fmt" "sync" "time" ) / ...

  6. golang中switch用法细节

    1. switch穿透-fallthrough, 如果在case语句块后增加fallthrough,则会继续执行下一个case,也叫switch穿透,默认只穿透一层 2. Type Switch: s ...

  7. 关于golang select的用法

    1 go的信道 1.1 什么是信道 信道可以理解为go协程之间进行通信的通道. 1.2 信道的声明 所有的信道都关联一个类型,一旦关联了类型,该信道就只能传输该类型的数据,传输其它类型的数据的话就是非 ...

  8. Golang omitempty 的用法

    原文链接:https://blog.csdn.net/skh2015java/article/details/90720692omitempty作用是在json数据结构转换时,当该字段的值为该字段类型 ...

  9. Go append 省略号

    1 前言 Golang append加...用法缘由 2 代码 type Product struct { ID int64 `json:"id"` Name string `js ...

  10. GO语言的进阶之路-面向对象编程

    GO语言的进阶之路-面向对象编程 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 当你看完这篇文章之时,我可以说你的Golang算是入门了,何为入门?就是你去看Docker 源码能看 ...

随机推荐

  1. 开发组件:REST API

    REST API 最佳入门指南 https://blog.csdn.net/px01ih8/article/details/78674685

  2. web基础 (一) http协议

    一.什么是web服务 浏览器与网页服务端发起的请求与回应(返回的是一堆字符串,浏览器去渲染生成页面!)都是 标准的CS模式 ---- bs模式:客户端用浏览器即可,服务端需要自己去写 http协议是建 ...

  3. css模拟下拉菜单

    <!DOCTYPE html > <head>     <meta http-equiv="Content-Type" content="t ...

  4. Jenkins配置HTML报告(Windows环境)

    1.首先安装插件HTML Publisher,点击直接安装 2.在任务中配置,构建后操作,添加Publish HTML reports 3.添加完成后,新增一项 4.HTML directory to ...

  5. pure框架

    内容: 1.介绍与入门 2.基础使用 参考资料: pure中文文档:https://www.purecss.cn/ pure实例:https://www.purecss.cn/layouts.html ...

  6. 多数据源springboot-jta-atomikos

    参考:  https://github.com/classloader/springboot-jta-atomikos-demo 參考:二 :建议参考  https://blog.csdn.net/a ...

  7. HTML5 Canvas 小例子 旋转的图片

    <一>CSS部分 @charset "utf-8"; *{ padding:; margin:; outline: none; } #canvas{ position: ...

  8. onMouseDown和onPress的差异AS2

    為了要做出比Button物件更複雜的互動,我們通常會改用MovieClip來製作按鈕.如此一來,就需要處理event handler.與滑鼠有關的MovieClip event handler包括on ...

  9. tensorflow UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

    tensorflow读取图像出现错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid s ...

  10. kafka相关资料

    先来说一下Kafka与RabbitMQ的对比: RabbitMQ,遵循AMQP协议,由内在高并发的erlanng语言开发,用在实时的对可靠性要求比较高的消息传递上. kafka是Linkedin于20 ...