Difference between revisions of "Or"

From Xojo Documentation

m (1 revision)
 
m
 
(26 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 +
{{OperatorBox}}
 +
{{Description
 +
|text = Used to perform a logical '''Or''' comparison between two [[Boolean]] expressions or a bitwise '''Or''' comparison between two [[Integer|integers]]. }}
  
 +
== Usage ==
 +
''result'' = ''expression1'' '''Or''' ''expression2''
 +
{| cellpadding="6" cellspacing="0" border="1"
  
=='''Description'''==
+
! width=15%  style="background-color:#e0e0e0" | Part
Used to perform a logical '''Or''' comparison between two [[Boolean|Boolean]] expressions or a bitwise '''Or''' comparison between two [[Integer|integers]].
 
 
 
 
 
 
 
=='''Syntax'''==
 
result=expression1 '''Or''' expression2
 
{| cellpadding="8" cellspacing="0" border="1"
 
 
 
! width=25%  style="background-color:#e0e0e0" | Part
 
  
 
! width=15%  style="background-color:#e0e0e0" | Type
 
! width=15%  style="background-color:#e0e0e0" | Type
Line 18: Line 15:
 
|result
 
|result
  
|[[Boolean|Boolean]] or [[Integer|Integer]]
+
|[[Boolean]] or [[Integer]]
|A [[Boolean|Boolean]] value if ''expression1'' and ''expression2'' are [[Boolean|boolean]] and an [[Integer|integer]] if ''expression1'' and ''expression2'' are [[Integer|integers]].
+
|A [[Boolean]] value if ''expression1'' and ''expression2'' are [[Boolean|boolean]] and an [[Integer|integer]] if ''expression1'' and ''expression2'' are [[Integer|integers]].
  
 
|-
 
|-
 
|expression1
 
|expression1
  
|[[Boolean|Boolean]] or [[Integer|Integer]]
+
|[[Boolean]] or [[Integer]]
|Any valid [[Boolean|Boolean]] or [[Integer|integer]] expression. ''Expression1'' and ''expression2'' must be of the same data type.
+
|Any valid [[Boolean]] or [[Integer|integer]] expression. ''Expression1'' and ''expression2'' must be of the same data type.
  
 
|-
 
|-
 
|expression2
 
|expression2
  
|[[Boolean|Boolean]] or [[Integer|Integer]]
+
|[[Boolean]] or [[Integer]]
|Any valid [[Boolean|Boolean]] or [[Integer|integer]] expression. ''Expression1'' and ''expression2'' must be of the same data type.
+
|Any valid [[Boolean]] or [[Integer|integer]] expression. ''Expression1'' and ''expression2'' must be of the same data type.
  
 
|-
 
|-
 
|}
 
|}
  
 +
== Notes ==
 +
The '''Or''' operator is overloaded. If it is passed two [[Boolean|booleans]], it performs a logical Or and returns a [[Boolean|boolean]]. If it is passed two [[Integer|integers]], it performs a bitwise Or operation on the [[Integer|integers]] and returns an [[Integer|integer]]. In this case, it is equivalent to calling the BitOr method of the [[Bitwise]] class.
  
=='''Notes'''==
+
In the first instance, if either boolean expression evaluates to [[True]], then ''result'' is [[True]]. If both expressions evaluate to [[False]] then ''result'' is [[False]]. The truth table for logical operators is shown below.
The '''Or''' operator is overloaded. If it is passed two [[Boolean|booleans]], it performs a logical Or and returns a [[Boolean|boolean]]. If it is passed two [[Integer|integers]], it performs a bitwise Or operation on the [[Integer|integers]] and returns an [[Integer|integer]]. In this case, it is equivalent to calling the BitOr method of the [[Bitwise|Bitwise]] class.
 
  
In the first instance, if either boolean expression evaluates to [[True|True]], then result is [[True|True]]. If both expressions evaluate to [[False|False]] then result is [[False|False]]. The truth table for REALbasic's logical operators is shown below.
 
 
{| cellpadding="8" cellspacing="0" border="1"  
 
{| cellpadding="8" cellspacing="0" border="1"  
  
! width=25%  style="background-color:#e0e0e0" | Expression1
+
! width=15%  style="background-color:#e0e0e0" | Expression1
  
! width=25%  style="background-color:#e0e0e0" | Expression2
+
! width=15%  style="background-color:#e0e0e0" | Expression2
  
! width=25%  style="background-color:#e0e0e0" | Or
+
! width=15%  style="background-color:#e0e0e0" | Or
  
! width=25%  style="background-color:#e0e0e0" | [[And|And]]
+
! width=15%  style="background-color:#e0e0e0" | [[And]]
  
! width=25%  style="background-color:#e0e0e0" | [[Xor|Xor]]
+
! width=15%  style="background-color:#e0e0e0" | [[Xor]]
 
|-
 
|-
 
|True
 
|True
Line 101: Line 98:
 
If you pass two [[Integer|integers]], '''Or''' returns an [[Integer|integer]] that is the result of comparing each bit of the two [[Integer|integers]] passed and assigning 1 to the bit position in the [[Integer|integer]] returned if either of the bits in the same position in the [[Integer|integers]] passed are 1. Otherwise, 0 is assigned to the bit position.
 
If you pass two [[Integer|integers]], '''Or''' returns an [[Integer|integer]] that is the result of comparing each bit of the two [[Integer|integers]] passed and assigning 1 to the bit position in the [[Integer|integer]] returned if either of the bits in the same position in the [[Integer|integers]] passed are 1. Otherwise, 0 is assigned to the bit position.
  
The following table shows the results for REALbasic's bitwise operators:
+
The following table shows the results for bitwise operators:
 
{| cellpadding="8" cellspacing="0" border="1"  
 
{| cellpadding="8" cellspacing="0" border="1"  
  
! width=25%  style="background-color:#e0e0e0" | Integer1
+
! width=15%  style="background-color:#e0e0e0" | Integer1
  
! width=25%  style="background-color:#e0e0e0" | Integer2
+
! width=15%  style="background-color:#e0e0e0" | Integer2
  
! width=25%  style="background-color:#e0e0e0" | Or
+
! width=15%  style="background-color:#e0e0e0" | Or
  
! width=25%  style="background-color:#e0e0e0" | [[And|And]]
+
! width=15%  style="background-color:#e0e0e0" | [[And]]
  
! width=25%  style="background-color:#e0e0e0" | [[Xor|Xor]]
+
! width=15%  style="background-color:#e0e0e0" | [[Xor]]
 
|-
 
|-
 
|0
 
|0
Line 160: Line 157:
 
|}
 
|}
  
 
+
== Sample Code ==
=='''Examples'''==
 
 
This example uses the '''Or''' operator to perform logical comparisons
 
This example uses the '''Or''' operator to perform logical comparisons
{| cellpadding="8" cellspacing="0" border="1"
 
|<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Dim|Dim]] a As [[Boolean|Boolean]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Dim|Dim]] b As [[Boolean|Boolean]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Dim|Dim]] c As [[Boolean|Boolean]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">[[Dim|Dim]] d As [[Boolean|Boolean]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">a=[[True|True]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">b=[[False|False]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">d=a '''Or''' b //Returns [[True|True]]<br /></div>
 
<div style="width:100%; background-color:#d0d0d0; padding-left:30px">d=b '''Or''' c //Returns [[False|False]]<br /></div>
 
 
|-
 
|}
 
.
 
 
  
 +
<rbcode>
 +
Var a As Boolean
 +
Var b As Boolean
 +
Var c As Boolean
 +
Var d As Boolean
 +
a = True
 +
b = False
 +
d = a Or b // d = True
 +
d = b Or c // d = False
 +
</rbcode>
  
=='''See Also'''==
+
Using Or with Integer values:
[[And|And]], [[Not|Not]], [[Xor|Xor]] operators; [[Bitwise|Bitwise]] class; [[Operator_Or|Operator_Or]] function; [[Operator|Operator]] precedence.
+
<rbcode>
 +
Var i1 As Integer = 4
 +
Var i2 As Integer = 5
 +
 
 +
Var result As Integer
 +
result = i1 Or i2 // result = 5
 +
</rbcode>
  
 +
== See Also ==
 +
[[And]], [[Not]], [[Xor]] operators; [[Bitwise]] class; [[Operator_Or]] function; [[Operator_Precedence|Operator precedence]]
  
[[Category:Boolean]]
+
[[Category:Language_Boolean]]
[[Category:Operators]]
 

Latest revision as of 20:02, 22 November 2019

Operator

Used to perform a logical Or comparison between two Boolean expressions or a bitwise Or comparison between two integers.

Usage

result = expression1 Or expression2

Part Type Description
result Boolean or Integer A Boolean value if expression1 and expression2 are boolean and an integer if expression1 and expression2 are integers.
expression1 Boolean or Integer Any valid Boolean or integer expression. Expression1 and expression2 must be of the same data type.
expression2 Boolean or Integer Any valid Boolean or integer expression. Expression1 and expression2 must be of the same data type.

Notes

The Or operator is overloaded. If it is passed two booleans, it performs a logical Or and returns a boolean. If it is passed two integers, it performs a bitwise Or operation on the integers and returns an integer. In this case, it is equivalent to calling the BitOr method of the Bitwise class.

In the first instance, if either boolean expression evaluates to True, then result is True. If both expressions evaluate to False then result is False. The truth table for logical operators is shown below.

Expression1 Expression2 Or And Xor
True True True True False
True False True False True
False True True False True
False False False False False

If you pass two integers, Or returns an integer that is the result of comparing each bit of the two integers passed and assigning 1 to the bit position in the integer returned if either of the bits in the same position in the integers passed are 1. Otherwise, 0 is assigned to the bit position.

The following table shows the results for bitwise operators:

Integer1 Integer2 Or And Xor
0 0 0 0 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 0

Sample Code

This example uses the Or operator to perform logical comparisons

Var a As Boolean
Var b As Boolean
Var c As Boolean
Var d As Boolean
a = True
b = False
d = a Or b // d = True
d = b Or c // d = False

Using Or with Integer values:

Var i1 As Integer = 4
Var i2 As Integer = 5

Var result As Integer
result = i1 Or i2 // result = 5

See Also

And, Not, Xor operators; Bitwise class; Operator_Or function; Operator precedence