Operators in X3

Logical Operators:

 codeExplainvar a = 5
var b = 10

if a > 0 and b > 0 then
    show("Both 'a' and 'b' are positive.")
end

if a == 5 or b == 5 then
    show("At least one of 'a' or 'b' is equal to 5.")
end

if not (a < 0) then
    show("'a' is not negative.")
end
  • X3 supports logical operators such as "and", "or", and "not".

  • These operators allow you to combine or negate conditions to create more complex expressions.

Comparison Operators:

 codeExplainif a == b then
    show("'a' is equal to 'b'.")
end

if a != b then
    show("'a' is not equal to 'b'.")
end

if a < b then
    show("'a' is less than 'b'.")
end

if a >= b then
    show("'a' is greater than or equal to 'b'.")
end
  • X3 also supports comparison operators like "==" (equality), "!=" (not equal), "<" (less than), ">" (greater than), "<=" (less than or equal), and ">=" (greater than or equal).

  • These operators are used to compare values and return a boolean result.

Combining Conditions:

 codeExplainif a > 0 and b < 10 then
    show("'a' is positive and 'b' is less than 10.")
end

if a > 0 or b < 10 then
    show("Either 'a' is positive or 'b' is less than 10.")
end
  • You can combine multiple conditions using logical operators to form more complex conditions.

Conditions in X3 are fundamental for creating dynamic and responsive programs, allowing you to control the flow of execution based on specific criteria or inputs. By using conditions effectively, you can create programs that adapt to different situations and requirements.

Last updated