Loop Start Index

 

The startindex() function sets the start index of an array for the current SPL function. For example:

 

func1(a)

{

    local i, b;

 

    startindex(0);

    b = 0;

 

    for (i = 0; i < length(a); i++)

    {

        b += a[i] * i;

    }

 

    return(b);

}

 

 

In this function, the array starting index is set to 0, so the first value of array a is referenced with a[0].

 

The startindex is automatically reset to the configuration parameter SPL_START_INDEX (default 1) when the function exits. The startindex function only effects the current SPL routine, routines called by the current function are not effected.

 

Startindex makes it easier to develop routines where a starting index other than 1 is more natural for the algorithm.