go语言的循环语句for

栏目: Go · 发布时间: 7年前

内容简介:版权声明:本文为博主原屙文章,喜欢你就担走。 https://blog.csdn.net/leftfist/article/details/84547716

版权声明:本文为博主原屙文章,喜欢你就担走。 https://blog.csdn.net/leftfist/article/details/84547716

一般来说,每种语言的循环语句都有两三种,什么for,foreach,while,do—until之类,应有尽有,总有一款适合您。但 go 是一款比较新的语言,语言的作者可能有一些自己的想法,循环语句就只提供了for一种。

suffixs := [6]string{".js",".css",".png",".jpg",".gif",".html"}
	for i := 0; i < len(suffixs); i++ {
		fmt.Println(suffixs[i])
	}

并且这个for是将foreach合而为一的。其他语言,像C#,foreach是很方便,但如果又想用到序号,就要在外面声明一个int i;然后循环体里i++之类,讨厌得很。但go版本的就挺好,可以将每轮迭代的序号和元素返回:

suffixs := [6]string{".js",".css",".png",".jpg",".gif",".html"}
	for i,sf := range suffixs{
		fmt.Printf("序号:%d,元素:%s\n\r",i,sf)	//注意%是写在前面的
	}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Ethnography and Virtual Worlds

Ethnography and Virtual Worlds

Tom Boellstorff、Bonnie Nardi、Celia Pearce、T. L. Taylor / Princeton University Press / 2012-9-16 / GBP 21.00

"Ethnography and Virtual Worlds" is the only book of its kind - a concise, comprehensive, and practical guide for students, teachers, designers, and scholars interested in using ethnographic methods t......一起来看看 《Ethnography and Virtual Worlds》 这本书的介绍吧!

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

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码