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?

13th Dec 2020, 1:18 AM
Pontus Holdo
2 Answers
+ 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
13th Dec 2020, 1:47 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar