Skip to content

Commit

Permalink
Add sample of logical operators in if statements
Browse files Browse the repository at this point in the history
Fixes #494
  • Loading branch information
eliben committed Oct 28, 2023
1 parent edab962 commit 41dd5d9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions examples/if-else/if-else.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/if-else/if-else.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
d6a962236fc1296684cd1ffb2d95d131ed84abde
U7xcpdutgCJ
152124e287cd55e549bc29bcb8693bf260d1b3ab
hTOHdmUcUxz
1 change: 1 addition & 0 deletions examples/if-else/if-else.sh
Original file line number Diff line number Diff line change
@@ -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:)
Expand Down
19 changes: 17 additions & 2 deletions public/if-else

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41dd5d9

Please sign in to comment.