Logical Operators
Part of the Fundamentals section of Coddy's Solidity journey. Lesson 17 of 53.
Combine boolean conditions with && for AND and || for OR. AND needs both sides to be true. OR needs at least one true side. Put ! before a boolean to reverse it. Parentheses make grouped comparisons easier to read.
The statements in this excerpt run inside the provided main function.
bool hasPass = true;
bool paused = false;
console.log(hasPass && !paused);The pass is present and the pause flag is false, so both requirements are satisfied after negating paused. AND and OR short-circuit: the right side is evaluated only when it can change the result.
AND requires both conditions; OR requires at least one condition.
Challenge
EasyA visitor may enter only when ticket is true and closed is false. Print whether entry is allowed.
The tests pass arguments to main in this order: bool ticket, bool closed. Each test starts with fresh contract state.
Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.
Try it yourself
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
function main(bool ticket, bool closed) external view {
// Write your solution here.
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
Practice on your own: Solidity playground