You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
325 B
Plaintext
24 lines
325 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)
|
|
}
|
|
}
|
|
|