Drop both init and post to get a while-style loop:
n := 1
for n < 100 {
n *= 2
}
fmt.Println(n)
This is how Go handles while loops. No semicolons needed when you only have a condition. The loop runs until n reaches or exceeds , then prints .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Condition-only loops
Drop both init and post to get a while-style loop:
n := 1
for n < 100 {
n *= 2
}
fmt.Println(n)
This is how Go handles while loops. No semicolons needed when you only have a condition. The loop runs until n reaches or exceeds , then prints .