How to implement these loops ...
Pyung-Chul Kim
pckim at unisql.UUCP
Fri Jun 21 08:53:42 AEST 1991
In article <12844 at skye.cs.ed.ac.uk>, scm at cs.ed.ac.uk (Santa C Maria) writes:
> for ( i[0] = 0; i[0] < x[0]; ++i[0] ) {
> for ( i[1] = 0; i[1] < x[1]; ++i[1] ) {
> ......
> for ( i[m-1] = 0; i[m-1] < x[m-1]; ++i[m-1] ) {
> do_something_here();
> }
> ......
> }
> }
>
> The problem is that m, x[0], ... x[m-1] all depend upon run-time
> values. The question is how do I code this?
>
After determine m and allocate array x, and initialize elements of it,
and call the following recursive funtion foo(0):
/* assume m and x are global variables */
foo(j)
int j;
{
int i;
if(j == m-1) for(i = 0; i < x[j]; i++) do_something_here(i,j);
else for(i = 0; i < x[j]; i++) foo(j+1);
}
Hope it helps
--
Pyung-Chul Kim
UniSQL, Inc.
9390 Research Blvd., Kaleido II, Suite 220, Austin, TX 78759
Internet: execu!sequoia!unisql!pckim at cs.utexas.edu
UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!pckim
TEL: (512)343-7297 Ext. 332
FAX: (512)343-7383
More information about the Comp.lang.c
mailing list