0
Single line if-statement
Is there any programming language where I absolutely must have the curly brackets in a single line if-statement to make it work?
2 Antworten
+ 1
I have been learning Go recently.
Go though primarily inspired by C, is very strict about it's coding style.
In Go, curly baraces are *must* for body of if statements. Also the starting baracket must be on same line as condition. However, you can omit the parentheses around condition. (If you add parentheses they are removed by go fmt tool anyaways. fmt tool formats go code to maintain consistent coding style)
An example of if-else in Go:
package main
func main(){
x:= 5
y:=2
if x > y {
//statements
} else {
//statements
}
}
https://tour.golang.org/flowcontrol/7
https://blog.golang.org/gofmt