| Cogitek RIATest 3 Documentation | Copyright © Cogitek Inc. |
Functions are typically used to create reusable blocks of script.
The syntax for function declaration is the following:
function functionName([parameter-name-1, parameter-name-2, ...])
{
// function code goes here
}
Once the function is declared it can be called from your script in exactly the same way that built-in Global functions are called, e.g.:
myFunc("123")
You can return a value from a function using a return statement, e.g.
function testFunc()
{
return 123;
}
Note that the function must be declared before it can be called, e.g. the following is not correct:
funcA("123");
function funcA(param)
{
}
This does not prevent you from having two functions calling each other. For example the following code is correct:
function funcA(param)
{
if (param>0) return funcB(param-1);
else return 0;
}
function funcB(param)
{
if (param>0) return funcA(param-1);
else return 0;
}
funcA(10);