-
Notifications
You must be signed in to change notification settings - Fork 524
Open
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
Description
Context: https://tour.golang.org/flowcontrol/7
The "}" closing brace of if
statement must be immediately followed by an else
statement if any. Writing else
on a separate line(like we do in Python, C, Java, etc) will generate a SyntaxError
in Go.
Example:
package main
import (
"fmt"
"math"
)
func pow(x, n, lim float64) float64 {
if v := math.Pow(x, n); v < lim {
return v
}
else { // misplaced "else" statement
fmt.Printf("%g >= %g\n", v, lim)
}
// can't use v here, though
return lim
}
func main() {
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20),
)
}
Output: prog.go:12:2: syntax error: unexpected else, expecting }
harsha-deep and MRX-72
Metadata
Metadata
Assignees
Labels
NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.