Skip to content

Checks and Conditionals

C272 edited this page Dec 18, 2019 · 2 revisions

In Algo, checks are written very similarly to C++, C# and many other modern languages. Here is a small example, involving an "if" statement.

let x = 3;
if (x == 3 | x == 123) {
    print "x is 3, or x is 123.";
}

The part inside the brackets after the "if" is the check. Written out in plain English, this check reads something like:

"If the value of 'x' is 3, or the value of 'x' is 123, then this check passes."

You use a double equals ("==") to check whether something is equal to something else, and a pipe ("|") to use a binary OR (eg. x is true OR y is true would be "x | y") You can also use brackets for precedence, much like in expressions. Below is a table of all the conditional check symbols used in Algo, for reference purposes.

Symbol (Example) "English" Meaning
x == y Is 'x' equal to 'y'?
x != y Is 'x' not equal to 'y'?
x < y Is 'x' less than 'y'?
x <= y Is 'x' less than or equal to 'y'?
x > y Is 'x' greater than 'y'?
x >= y Is 'x' greater than or equal to 'y'?
x & y Is 'x' true and 'y' true?
x | y Is 'x' true or 'y' true?
!x Is the inverse of 'x' true?
x Is 'x' true?