Boolean type
In Go, Boolean binary values are stored using the bool
type. Although a variable of type bool
is stored as a 1-byte value, it is not, however, an alias for a numeric value. Go provides two pre-declared literals, true
and false
, to represent Boolean values as shown in the following example:
package main import "fmt" func main() { var readyToGo bool = false if !readyToGo { fmt.Println("Come on") } else { fmt.Println("Let's go!") } }
golang.fyi/ch04/bool.go
Get Learning Go Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.