Skip to content

Expressions

C272 edited this page Aug 19, 2019 · 2 revisions

Expressions in Algo are any calculations which return a value to be used. For example, when you set a variable, the right hand side of the statement is an expression, as seen below.

let x = 3 + 2; //"3 + 2" is the expression

There are several different operators that can be used in expressions, some of which have different precedence levels than others (eg. powers are evaluated before addition), which are listed below. Higher precedence level means they are evaluated first.

Symbol (Example) "English" Meaning Precedence Level
x + y Add 'y' to 'x'. 0
x - y Subtract 'y' from 'x'. 0
x * y Multiply 'x' by 'y'. 1
x / y Divide 'x' by 'y'. 1
x % y Remainder 'x' by 'y'. 1
x ^ y Raise 'x' to power 'y'. 2