zl程序教程

您现在的位置是:首页 >  后端

当前栏目

[Go] using For loop as While loop

Go for Using as while loop
2023-09-14 08:59:12 时间

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))
	}
}