Or operator: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>MrNicNac
No edit summary
>MrNicNac
No edit summary
Line 1: Line 1:
The or statement comes in handy when you want to check if one of the listed values is a certain value.
The or statement comes in handy when you want to check if one of the listed values is a certain value.
 
== If Statement ==
<pre>
<pre>
soul = true
soul = true
Line 16: Line 16:
</pre>
</pre>


== Choice of Value ==
The or statement can also be used to choose an existent value of a nil value. Here is an example:
The or statement can also be used to choose an existent value of a nil value. Here is an example:
<pre>
<pre>

Revision as of 19:11, 9 July 2011

The or statement comes in handy when you want to check if one of the listed values is a certain value.

If Statement

soul = true
food = false
try = false

if soul == true or food == true or try == true then -- If any of the three comparisons are met, then continue with the code block
    print 'soul is always true'
end


Output:
> soul is always true

Choice of Value

The or statement can also be used to choose an existent value of a nil value. Here is an example:

local y = x or 1
print(y)
> 1

This printed '1' because variable 'x' doesn't exist and is therefore nil. So the or operator allowed us to choose 1 over nil.