JEXL - the backbone of IMCScript provides 3 most important conditional syntax.
If-Else Statements
If-Else statements help to perform logic based on certain condition. Below is simple example of if-else conditions to check if number is Odd or Even.
Alternatively, user can also have multiple else-if statements. Here is an example which sets fruit according to season.
For Loop
For loop helps to iterate List type of object and perform specific logic for each of its element. For example, below code iterates through each element of list and sums values in variable sum.
While Loop
While loop helps to iteratively perform required logic until specific condition is not violated. Here is an example, which uses while loop to iterate through numbers until it doesn’t find square-root of given number.
Alternatively continue and break are useful reserved keywords which helps to skip or break the loops unconditionally. Calculable usage of these keywords improves script execution time by skipping / breaking execution of insignificant loops.
Below script iterates list of elements and finds sum of only positive numbers. It uses continue to skip negative numbers.
Below script finds number in list and breaks loop using break keyword, once it finds number inside list.
Custom Functions
Custom or User-defined functions helps user to re-use custom logic frequently under the same script. It also increases readability for the script. Here is an example which defines 2 simple custom functions: sum and multiplication, for 2 numbers. Important thing to note here is, definition of function should be before the usage of it.
Comments
0 comments
Article is closed for comments.