Logical Operations
Learn how to use logical operations in your programs.
Reference
Name | Operation | Description |
Equals | = | Pops the last 2 items from the stack and pushes true if they are equal, or false otherwise. Works with both numbers and strings. |
Less Than | < | Pops the last 2 numbers from the stack and pushes true if the first is less than the second, or false otherwise. |
Greater Than | > | Pops the last 2 numbers from the stack and pushes true if the first is greater than the second, or false otherwise. |
Greater Than or Equal To | >= | Pops the last 2 numbers from the stack and pushes true if the first is greater than or equal to the second, or false otherwise. |
Less Than or Equal To | <= | Pops the last 2 numbers from the stack and pushes true if the first is less than or equal to the second, or false otherwise. |
Not Equals | != | Pops the last 2 items from the stack and pushes true if they are not equal, or false otherwise. Works with both numbers and strings. |
Is Nil | ? | Pops the last item on the stack and pushes true if the item in question is nil , otherwise false . |
Usage
Use logical operations to evaluate conditions in your programs. Here are a few examples:
# Checking equality between numbers
10 10 = # The stack now contains: 1
# Comparing strings
"hello" "world" != # The stack now contains: 1
# Using greater than comparison
# Remember about LIFO, the order is reversed, it is 10 > 15 and not 15 > 10
15 10 > # The stack now contains: 0