Serververwaltung > Automate Tasks and Calculate Data Using Event Triggers > What Is an Event Trigger? > Control Structures and Functions
  
Control Structures and Functions
To execute code a specified number of times while a condition is true, use the while loop, for example:
while (var<=endvalue) {
// Code to be executed
}
To hold reusable JavaScript code, use a function, for example:
function functionname (var1,var2,…,varX) {
// Code to be executed
return value
}

var functionvalue = functionname (var1,var2,…,varX)
Note the following:
A do…while loop is available, although it is rarely used. The do…while loop always executes at least once, even if the condition is false.
Be careful using a while loop. If you notice that the trigger script is taking too long or slowing down the server considerably, check to make sure any while loops are not stuck repeating continuously.
Like variables, function names are case-sensitive and can be the cause of script bugs.
Parameters and the return statement in a function are optional. You can have a function that does not need any parameters or returns any value.