I have a set of records with a field (corner increment) containing an integer number, always positive and never zero. I need a script to find the set of records, going backwards from the current record where the total of corner increment is equal to or more than the global value in corner basket.

I think I’m asking for an iteration routine but I don't know much about those. Any help appreciated.

While ( [
b = increment basket ;
i = corner increment ;
f = Get ( FoundCount ) ;
n = 0
] ;
b > i and
n < f
; [
n = n + 1 ;
i = i + GetNthRecord ( Record::corner increment ; f - n )
] ;
n /* + If ( n < f ; 1 ) / / add this in case the current record must be included */
)