2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-17 09:25:32 +00:00
cheat.sheets/sheets/_go/if
terminalforlife ade78aaafb Mass-replace tabs with 4-width spacing
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.
2020-03-01 00:21:26 +00:00

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