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.")
endIn this example, the condition
x > 5is 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.")
endHere, if the condition
y > 5is 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.")
endThe "elif" statement allows you to check additional conditions if the preceding ones are false.
In this example, if
zis positive, the first block is executed. If it's negative, the second block is executed. Otherwise, the last block is executed.
Last updated