Conditionals
Like other programming languages, conditionals are supported in Notes Calculator.
The first two fundamental values you need to know are true and false. These values are used to represent the truthiness of a condition.
true | truefalse | falseComparison Operators
Section titled “Comparison Operators”Comparison operators are used to compare two values and return a boolean result (true or false).
| Operator | Name | Behaviour |
|---|---|---|
== | Equal to | Returns true if left value and right value are equal |
!= | Not equal to | Returns true if left value and right value are not equal |
> | Greater than | Returns true if the left value is greater than the right value |
< | Less than | Returns true if the left value is less than the right value |
>= | Greater than or equal to | Returns true if the left value is greater than or equal to the right value |
<= | Less than or equal to | Returns true if the left value is less than or equal to the right value |
For example:
1 == 1 | true1 != 2 | true1 < 2 | true2 < 1 | false1 >= 1 | true2 <= 2 | trueLogical Operators
Section titled “Logical Operators”Logical operators are used to combine multiple conditions. The result is true if the combined condition
| Operator | Name | Behaviour |
|---|---|---|
&& or and | and | Returns true if both conditions are true |
|| or or | or | Returns true if at least one condition is true |
1 == 1 && 2 == 2 | true1 == 1 and 2 != 2 | false1 == 1 || 2 != 2 | true1 != 1 or 2 != 2 | falseif, else, then
Section titled “if, else, then”The if, else, and then keywords are used to control the flow of execution based on conditions.
earnings = $25k | $25,000if earnings > $30k then tax = 15% else tax = 5% | 5%earnings x tax | $1,250Declare a variable using a conditional
Section titled “Declare a variable using a conditional”income = $40k | $40,000expenses = $25k | $25,000profitable = true if income > expenses | trueinsolvent = false unless expenses > income | false