首页 > 其他分享 >[Go] using For loop as While loop

[Go] using For loop as While loop

时间:2022-09-04 16:47:41浏览次数:55  
标签:index myTxt fmt While Go using loop

There is no While loop in Go, but you can use For loop as while loop:

i := 1

for i < 100 {
    fmt.Println(i)
    i += 1
}

 

func main() {
	var myTxt = "This is a sentence"

	for index, letter := range myTxt {
		fmt.Println("Index:", index, "Letter: ", string(letter))
	}
}

 

标签:index,myTxt,fmt,While,Go,using,loop
From: https://www.cnblogs.com/Answer1215/p/16655370.html

相关文章

  • [Go] switch - fallthrough
    fallthrough keywordisusedinswitchstatementingolang.Thiskeywordisusedinswitchcaseblock.Ifthe fallthrough keywordispresentinthecasebloc......
  • [Go] Variables - non-declaration statement
    packagemainimport( "fmt")funcmain(){varfirstNamestring="firstName"varlastName="lastName"varfullNamestring//Gowillassignd......
  • [Go] Types - Reflect.TypeOf()
    Canusereflect.TypeOftogetvariabletypepackagemainimport( "fmt" "reflect")funcmain(){ //varageint=21 //varbbool=age>=23 varage......
  • shopee golang开发一面
    1、有环链表一个有环的链表,如何确认链表有环,环的长度。2、hashmap设计一个hashmap,你要用什么数据结构能用数组能做为存储hashmap的数据结构吗?不能的话,要怎么做?怎么解决......
  • golang面试经验2
    1、make和new的区别? 宝典导航2、了解过golang的内存管理吗?宝典导航3、调用函数传入结构体时,应该传值还是指针?说出你的理由?宝典导航4、线程有几种模型?宝典导航5、Go......
  • golang面试题2
    1、go方法值接收者和指针接收者结论:如果方法的接收者是指针类型,无论调用者是对象还是对象指针,修改的都是对象本身,会影响调用者      如果方法的接收者是值类......
  • 将 Go 类型打印为 S-Expressions
    将Go类型打印为S-ExpressionsPhotoby西格蒙德on不飞溅如果您已经使用Go一段时间,您可能知道当您使用“fmt”包渲染到控制台时,您可以从go结构中获得合理的输......
  • Could not find artifact org.pentaho:pentaho-aggdesigner-algorithm:pom:5.1.5-jhyd
    在Spark连接Hive导入相关maven依赖时<dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>2.3.4</version></de......
  • raise ConfigurationError(self._incompatible_err) pymongo.errors.ConfigurationErr
    python3ErrorFile"/home/xxx/.local/lib/python3.10/site-packages/pymongo/topology_description.py",line155,incheck_compatibleraiseConfigurationErr......
  • Django 与 Vue 语法冲突问题完美解决方法
    Django与Vue语法冲突问题完美解决方法当我们在djangoweb框架中,使用vue的时候,会遇到语法冲突.因为vue使用{{}},而django也使用{{}},因此会冲突.......