Using Operators
Operators are special symbols or keywords that perform operations on one or more values (operands) to produce a result. Ry supports a standard set of arithmetic, comparison, and logical operators.
Arithmetic Operators
These operators are used to perform mathematical calculations on
Number types.
+(Addition)-(Subtraction)*(Multiplication)/(Division)%(Modulo - remainder of a division)
data a = 10
data b = 3
out(a + b) # 13
out(a * 2) # 20
out(a % b) # 1
Comparison Operators
Comparison operators are used to compare two values. These expressions
always evaluate to a Boolean (true or
false).
==(Equal to)!=(Not equal to)<(Less than)>(Greater than)<=(Less than or equal to)>=(Greater than or equal to)
data score = 95
data passingScore = 70
out(score >= passingScore) # true
out("hello" == "world") # false
Logical Operators
Logical operators are used to combine or invert boolean values. They are essential for building complex conditions, especially in control flow.
and(Logical AND)or(Logical OR)not(Logical NOT)
data hasKey = true
data doorLocked = true
data canEnter = hasKey and not doorLocked
out(canEnter) # false
Bitwise Operators
For low-level manipulation of numbers, Ry provides bitwise operators. These treat numbers as a sequence of binary bits.
&(Bitwise AND)|(Bitwise OR)^(Bitwise XOR)~(Bitwise NOT)<<(Left Shift)>>(Right Shift)
data a = 5 # 0101 in binary
data b = 3 # 0011 in binary
out(a & b) # 1 (0001)
out(a | b) # 7 (0111)
out(a ^ b) # 6 (0110)
out(~a) # -6 (due to two's complement)
out(a << 1) # 10 (1010)
out(a >> 1) # 2 (0010)
Now that you know how to work with data, it's time to organize your code into reusable blocks in the Functions section.
Next: Functions!