
Try to think through the following conditionals before trying them out the playgroud. Will they evaluate to true or false?
package main
import (
"fmt"
)
func main() {
fmt.Println(true && true)
fmt.Println(true && false)
fmt.Println(true || true)
fmt.Println(true || false)
fmt.Println(!true)
}
&& 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.
package main
import (
"fmt"
)
func main() {
fmt.Printf("true && true\t %v\n", true && true)
fmt.Printf("true && false\t %v\n", true && false)
fmt.Printf("true || true\t %v\n", true || true)
fmt.Printf("true || false\t %v\n", true || false)
fmt.Printf("!true\t\t\t %v\n", !true)
}
About the author
- DevRel at StackGen | Formerly at Deepfence ,Tenable , Accurics | AWS Community Builder also Docker Community Award Winner at Dockercon2020 | CyberSecurity Innovator of Year 2023 award by Bsides Bangalore | Docker/HashiCorp Meetup Organiser Bangalore & Co-Author of Learn Lightweight Kubernetes with k3s (2019) , Packt Publication & also run Non Profit CloudNativeFolks / CloudSecCorner Community To Empower Free Education reach out me twitterhttps://twitter.com/sangamtwts or just follow on GitHub -> https://github.com/sangam14 for Valuable Resources
Comments
Join the discussionNo comments yet. Be the first to comment.



