[Go] using For loop as While 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))
	}
}

 

posted @ 2022-09-04 16:29  Zhentiw  阅读(11)  评论(0编辑  收藏  举报