For, Else If and Switch/Case support for Macro Language
April 24, 2021
Today Macro Language gets a major update with many new features that makes building macros easier than ever.
For Loop
Macro Language had
ForEach statement to loop over an array, and
While statement for any other loops. With this update, it now has support for
For statement which works similar to many other programming languages. Here is an example of how this can make things easier:
Old
New
$sum = 0
$i = 0
While ($i <= 10)
$sum += $i
$i += 1
$sum = 0
For ($i = 1, $i <= 10, ++$i)
$sum += $i
Else If
Another addition to the Macro Language is
Else If statement. This makes checking multiple conditions much easier compared to what was possible with the old nested If/Else statements
Switch/Case
Similar to If/Else If/Else structure, you can also now use
Switch/
Case/
Default structure if you are always comparing the same value. Note that Switch/Case requires
Break statements to stop processing a Case, otherwise it moves onto the next Case:
Increment/Decrement Operators
Yet another addition is the increment and decrement operators, which can be either pre-increment/decrement or post-increment/decrement. As in many similar languages, pre-increment/decrement operators will modify the value before returning it while post-increment/decrement operators will do so after returning the original value.
Old
New
$a += 1
$b = $a
$a -= 1
$b = $a
$b = $a
$a += 1
$b = $a
$a -= 1
$b = ++$a
$b = --$a
$b = $a++
$b = $a--
Operator Precedence
The final part of this update introduces
operator precedence.
In macro expressions, following operator precedence rules apply. The order of operations can be changed
by providing parantheses. The
Expression Editor
automatically fully parenthesizes any expression so that what operator precedence rules were used
is obvious. If you type 5 == 2 + 3 * 4 to Expression Editor it will automatically parse and convert
it to 5 == (2 + (3 * 4)).
Precedence | Category | Operators |
1 | Increment/Decrement | ++ | –– | | | | | | | |
2 | Unary | ! | – | + | | | | | | |
3 | Product | * | / | % | | | | | | |
4 | Sum & Concatenation | + | – | & | | | | | | |
5 | Comparison | == | != | < | <= | > | >= | | | |
6 | Logical And | && | | | | | | | | |
7 | Logical Or | || | | | | | | | | |
8 | Ternary | ?: | | | | | | | | |
9 | Assignment | = | += | –= | *= | /= | %= | &&= | ||= | &= |
Comments