Siebel eScript Language Reference > Siebel eScript Language Overview > Functions in Siebel eScript >

Function Recursion in Siebel eScript


A recursive function is a function that calls itself or that calls another function that calls the first function. Recursion is permitted in Siebel eScript. Each call to a function is independent of any other call to that function. However, recursion has limits. If a function calls itself too many times, a script runs out of memory and aborts.

Remember that a function can call itself if necessary. For example, the following function, factor(), factors a number. Factoring is a good candidate for recursion because it is a repetitive process where the result of one factor is then itself factored according to the same rules.

function factor(i) //recursive function to print factors of i,
{// and return the number of factors in i
   if ( 2 <= i )
{
      for ( var test = 2; test <= i; test++ )
{
         if ( 0 == (i % test) )
{
// found a factor, so print this factor then call
// factor() recursively to find the next factor
         return( 1 + factor(i/test) );
}
}
}
// if this point was reached, then factor not found
   return( 0 );
}

Siebel eScript Language Reference