shou2017.com
JP

Logical Operators && and || Frequently Asked in Ruby Silver Exam

Mon Feb 26, 2018
Sat Aug 10, 2024

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 &&.

&& Operator

The && operator skips evaluating the right-hand side if the left-hand side evaluates to false and proceeds to the next process.

|| Operator

The || operator skips evaluating the right-hand side if the left-hand side evaluates to true and proceeds to the next process.

| Operator and & Operator

The | operator and & operator evaluate both sides regardless of the evaluation result of the left-hand side. In other words, both sides are executed.

[改訂2版]Ruby技術者認定試験合格教本

See Also