Skip to content

Commit ab892b9

Browse files
author
theunicorndev237
committed
logical operators
1 parent 2eda647 commit ab892b9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Diff for: 008

Whitespace-only changes.

Diff for: 008-logical-operators.sol

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
3+
pragma solidity >=0.7.0 <0.9.0;
4+
5+
/**
6+
* Logical operators
7+
*/
8+
9+
contract LogicalOperators {
10+
uint256 public a = 5;
11+
uint256 public b = 10;
12+
13+
// logical not
14+
function logicalNot() public view returns (bool) {
15+
if (!(a > b)) {
16+
return true;
17+
}
18+
return false;
19+
}
20+
21+
// AND: &&
22+
function logicAND() public view returns (bool) {
23+
// both conditions must be fulfilled
24+
if ((a > b) && (a == b)) {
25+
return true;
26+
}
27+
return false;
28+
}
29+
30+
// OR: &&
31+
function logicOR() public view returns (bool) {
32+
// atleast one condition should be fulfilled
33+
if ((a > b) || (a == b)) {
34+
return true;
35+
}
36+
return false;
37+
}
38+
}

0 commit comments

Comments
 (0)