13. Boolean

Boolean(bool) Type

Boolean has only two possible values, true and false
Conditions and comparison operators needs value to be bool Type.
main.go
1
package main
2
3
import "fmt"
4
5
func main() {
6
var shouldGo bool = true
7
8
if shouldGo {
9
fmt.Println("I should Go!")
10
}
11
12
}
Copied!

Declaring Boolean

Boolean are declared using one of the following ways:
main.go
1
var shouldBe bool = true
2
var shouldBe = true
3
shouldBe :=true
Copied!
Zero value for bool is false
Last modified 2yr ago