A summary of questions involving the && and || operators.
These types of questions are commonly asked:
Choose the appropriate code to write in X so that the following execution result is achieved.
y = false
y X raise "failed"
puts("Success")
Execution result:
=> Success
By the way, the answer to this question is &&
.
The && operator skips evaluating the right-hand side if the left-hand side evaluates to false and proceeds to the next process.
The || operator skips evaluating the right-hand side if the left-hand side evaluates to true and proceeds to the next process.
The | operator and & operator evaluate both sides regardless of the evaluation result of the left-hand side. In other words, both sides are executed.