Conditions in X3

In X3, conditions are expressions that evaluate to either true or false. They are used to control the flow of execution in a program based on whether certain criteria are met. Conditions are commonly used with control flow statements such as "if", "elif" (short for "else if"), and "else". Here's how conditions work in X3:

Basic "if" Statement:

 codeExplainvar x = 10

if x > 5 then
    show("x is greater than 5.")
end
  • In this example, the condition x > 5 is evaluated.

  • If the condition is true, the code block inside the "if" statement is executed. Otherwise, it's skipped.

"if-else" Statement:

 codeExplainvar y = 3

if y > 5 then
    show("y is greater than 5.")
else
    show("y is not greater than 5.")
end
  • Here, if the condition y > 5 is true, the first code block is executed. Otherwise, the code block after "else" is executed.

"elif" Statement:

 codeExplainvar z = 0

if z > 0 then
    show("z is positive.")
elif z < 0 then
    show("z is negative.")
else
    show("z is zero.")
end
  • The "elif" statement allows you to check additional conditions if the preceding ones are false.

  • In this example, if z is positive, the first block is executed. If it's negative, the second block is executed. Otherwise, the last block is executed.

Last updated