Case 1
This program compiles successfully:
package main
import (
"fmt"
)
func main() {
i := 0
for ; i < 3; i++ {
fmt.Println(i)
}
}
Case 2
But this does not:
package main
import (
"fmt"
)
func main() {
i := 0
for ; i < 3; i++
{
fmt.Println(i)
}
}
This leads to error:
./prog.go:9:18: syntax error: unexpected newline, expecting { after for clause
Case 3
But this compiles successfully:
package main
import (
"fmt"
)
func main() {
i := 0
for
{
fmt.Println(i)
}
}
Question
Why is it that in case 2, the opening brace for for
is not allowed in the next line but in case 3 it is allowed?