If Statements
If-statement syntax
if <expr> {
<if statement body>
}
elif <expr> {
<else if statement body>
}
else {
<else statement body>
}
Working Example
package main
import "fmt" as fmt
fun Unit main() {
let isInRelationship = false
let isProgrammer = true
if isProgrammer && !isInRelationship {
fmt.println("Makes sense")
}
elif !isProgrammer && isInRelationship {
fmt.println("Makes sense")
}
elif !isProgrammer && !isInRelationship {
fmt.println("It's ok, it won't be hard for you to find a relationship")
}
else {
fmt.println("Stop lying")
}
}
package main
import fmt "fmt"
func main() {
isInRelationship := false
isProgrammer := true
if isProgrammer && !isInRelationship {
fmt.Println("Makes sense")
} else if !isProgrammer && isInRelationship {
fmt.Println("Makes sense")
} else if !isProgrammer && !isInRelationship {
fmt.Println("It's ok, it won't be hard for you to find a relationship")
} else {
fmt.Println("Stop lying")
}
// Eliminates any 'unused variable' errors
_, _ = isInRelationship, isProgrammer
}
Makes sense
Last updated