Conditional Logic Operators

Part of Golang Mastery course

~15 min read
Interactive
Hands-on
Beginner-friendly

Try to think through the following conditionals before trying them out the playgroud. Will they evaluate to true or false?

example.go
package main
 
import (
string">"fmt"
)
 
func main() {
fmt.Println(true && true)
fmt.Println(true && false)
fmt.Println(true || true)
fmt.Println(true || false)
fmt.Println(!true)
}
 

playground

&& will return true if both sides evaluate to true, otherwise it will return false.

|| will return true if either side evaluates to true.

! returns the opposite

Try some examples for yourself.

example.go
package main
 
import (
string">"fmt"
)
 
func main() {
fmt.Printf(string">"true && true\t %v\n", true && true)
fmt.Printf(string">"true && false\t %v\n", true && false)
fmt.Printf(string">"true || true\t %v\n", true || true)
fmt.Printf(string">"true || false\t %v\n", true || false)
fmt.Printf(string">"!true\t\t\t %v\n", !true)
}
 

playground

Your Progress

25 of 103 modules
24%
Started24% Complete
Previous
SpaceComplete
Next