Commands
Prev
Next

Commands

Various structure commands are supported. They can be freely nested.

There are also three special commands: exit, break and continue. The first one ends script execution and returns. The second exits current block (while, for or foreach and the third exits just a current step, restarting from the beginning of the loop.

if

Command if has following syntax:

if condition then code elseif condition then code else code endif

Both elseif and else parts are optional. Condition is any expression. Code is executed if condition is true. That means:

  • non-zero for integers and double

  • non-empty for strings

if a * 2 > 7 then
   b = 1
elseif a < 0 then
   b = 2
elseif 
   b = 0
endif

while

while condition do code end

Condition is recalculated each time loop is executed.

while i < 15 do
  i = i + a
end  

for

Command for has following syntax:

for variable = start value to end value step expression do code end

Loop is executed starting from start value and it is ended when variable's value is bigger then end value. If step part is specified, on each step variable's value is increased by given value instead of 1.

foreach i = 1 to 20 step 5 do
  a = a + 2 * i
end  

foreach

Command foreach has following syntax:

for variable in array do code end

Loop is executed for each key in given array. In each step variable is assigned the next key from the array.

sum = 0
foreach i in myArray do 
  sum = sum + myArray[i]
end  

Prev
Next
Home


Would you like to comment or contribute an update to this page?
Send feedback to the TDE Development Team