
Manual:Scripting
33
Loops and conditional statements
Command Syntax Description
do..while :do { <commands> } while=( <conditions> ); :while (
<conditions> ) do={ <commands> };
execute commands until given
condition is met.
for :for <var> from=<int> to=<int> step=<int> do={ <commands> } execute commands over a given
number of iterations
foreach :foreach <var> in=<array> do={ <commands> }; execute commands for each elements
in list
Command Syntax Description
if :if(<condition>) do={<commands>}
else={<commands>} <expression>
If a given condition is true then execute commands in the do block,
otherwise execute commands in the else block if specified.
Example:
{
:local myBool true;
:if ($myBool = false) do={ :put "value is false" } else={ :put "value is true" }
}
Functions
Scripting language does not allow to create functions directly, however you could use :parse command as a
workaround.
Starting from v6.2 new syntax is added to easier define such functions and even pass parameters. It is also possible
to return function value with :return command.
See examples below:
#define function and run it
:global myFunc do={:put "hello from function"}
$myFunc
output:
hello from function
#pass arguments to the function
:global myFunc do={:put "arg a=$a"; :put "arg '1'=$1"}
$myFunc a="this is arg a value" "this is arg1 value"
output:
arg a=this is arg a value
arg '1'=this is arg1 value
Notice that there are two ways how to pass arguments:
•• pass arg with specific name ("a" in our example)
•• pass value without arg name, in such case arg "1", "2" .. "n" are used.
Return example
Commenti su questo manuale