/* Recursive 'Flexible' N-base Dimension Indexing (overflow-free) */ new; cls; x={0,0,0,0,0}; NN={10,5,3,2,5}; print x'; do while not x==(NN-1); x=recXindex(x,NN); print x'; endo; /* ** recXindex.txt - Recursive Flexible N-base Dimension Indexing. ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Gets flexible N-base index numbers for given dimension recursively ** without overflow problem. ** ** Format: x=recXindex(x,NN); ** ** Input: x vector, dim x 1 of current flexible N-base index vector ** ** NN vector, dim x 1 of base numbers ** ** Output: x vector, dim x 1 of next N-base index vector ** ** Notice: You could start from x={0,0,0,0,0}; for example. */ proc recXindex(x,NN); local dim,j; dim=rows(x); x[dim]=x[dim]+1; j=dim; do until j==0; if x[j]==NN[j]; x[j]=0; x[j-1]=x[j-1]+1; endif; j=j-1; endo; retp(x); endp;