while loop

suggest change

Go doesn’t have while loops because they can be written as for loops.

For example, this C++ while loop:

int n = 0;
while (n < 3) {
    printf("n: %d\n", n);
    n++;
}

can be written as for loop:

n := 0
for n < 3 {
	fmt.Printf("n: %d\n", n)
	n++
}
n: 0
n: 1
n: 2

A more concise version:

for n := 0; n < 3; n++ {
	fmt.Printf("n: %d\n", n)
}
n: 0
n: 1
n: 2

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents