mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-17 09:25:32 +00:00
ade78aaafb
This seems to be the predominant choice, and matches the last commit I just made, so I went ahead and converted them all, and changed any, - for example, 2-space indents. Let me know if this is undesired. To understand why I chose to do this, please refer to the previous commit's message.
24 lines
397 B
Plaintext
24 lines
397 B
Plaintext
func main() {
|
|
// Basic one
|
|
if x > 0 {
|
|
return x
|
|
} else {
|
|
return -x
|
|
}
|
|
|
|
// You can put one statement before the condition
|
|
if a := b + c; a < 42 {
|
|
return a
|
|
} else {
|
|
return a - 42
|
|
}
|
|
|
|
// Type assertion inside if
|
|
var val interface{}
|
|
val = "foo"
|
|
if str, ok := val.(string); ok {
|
|
fmt.Println(str)
|
|
}
|
|
}
|
|
|