Changes

Understanding Ruby Logical Operators

5 bytes added, 12:48, 1 December 2007
no edit summary
''Logical Operators'' are also known as ''Boolean Operators'' because they evaluate parts of an expression and return a ''true'' or ''false'' value, allowing decisions to be made about how a script program should proceed.
The first step to understanding how logical operators work in Ruby is to construct a sentence rather than to look at a script code example right away. Let's assume we need to check some aspect of two variables named var1 and var2. Our sentence might read:
''If var var1 is less than 25 AND var2 is greater than 45 then return true''
Here the logical operator is the "AND" part of the sentence. If we were to express this in Ruby we would use the comparison operators we covered earlier together with the ''and'' or ''&&'' logical operators:
</pre>
Another usefulLogical useful ''Logical Operator '' is the ''not'' operator which simply inverts the result of an expression. The ! character represents the NOT operator and can be used as follows:
<pre>