There are several differences in syntax between an if statement in Cicada and one in C. Firstly, the logical test is between the if and a then keyword, rather than being inside parentheses.
if a == b then print("They're equal.\n")
Secondly, some of the logical operators are different. ‘and’, ‘or’, ‘xor’ and ‘not’ are all written out in words, and the is-not-equal operator is /=, not !=. Cicada also has the reference-comparison operators ‘== @’ and ‘/= @’ (see aliases).
if a == @nothing and b /= @nothing then print("a, but not b, is void.")
Third, since the entire if statement is one single command and (unlike in C) a line break ends commands, if we want to break it over several lines we need to either use a ‘&’ which continues lines, or else parentheses beginning on the line of the if statement.
if a == b then &
print("They're equal.\n")
else if a /= b then (
print("They're different.\n")
)
Finally, the latter method shows how to write multi-line if statements: using parentheses instead of curly braces. (Technical note: while curly braces actually work for most if statements, they also produce a new variable space, so defining new members or using the keyword this won’t do what you expect. Just use parentheses.)
if a /= @nothing and b /= @nothing then ( | avoid a crash
if a == @b then print("They're the same variable!\n")
else if a == b then print("They're equal.\n")
else print("They're different.\n") )
else print("At least one of these members is VOID!")
Last update: May 8, 2024