Single line if-statement | Sololearn: Learn to code for FREE!


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?

12/13/2020 1:18:33 AM

Pontus Holdo

2 Answers

New Answer


C styled languages usually ignore spaces and blank lines.


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 } }