Add sample of logical operators in if statements

Fixes #494
This commit is contained in:
Eli Bendersky
2023-10-28 08:18:19 -07:00
parent edab962054
commit 41dd5d97b1
4 changed files with 26 additions and 4 deletions

View File

@@ -19,6 +19,12 @@ func main() {
fmt.Println("8 is divisible by 4")
}
// Logical operators like `&&` and `||` are often
// useful in conditions.
if 7%2 == 0 || 8%2 == 0 {
fmt.Println("either 8 or 7 are even")
}
// A statement can precede conditionals; any variables
// declared in this statement are available in the current
// and all subsequent branches.

View File

@@ -1,2 +1,2 @@
d6a962236fc1296684cd1ffb2d95d131ed84abde
U7xcpdutgCJ
152124e287cd55e549bc29bcb8693bf260d1b3ab
hTOHdmUcUxz

View File

@@ -1,6 +1,7 @@
$ go run if-else.go
7 is odd
8 is divisible by 4
either 7 or 8 are even
9 has 1 digit
# There is no [ternary if](https://en.wikipedia.org/wiki/%3F:)