Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!chinacat!sequoia!unisql!pckim From: pckim@unisql.UUCP (Pyung-Chul Kim) Newsgroups: comp.lang.c Subject: Re: How to implement these loops ... Summary: recursion Message-ID: <1377@unisql.UUCP> Date: 20 Jun 91 22:53:42 GMT References: <12844@skye.cs.ed.ac.uk> Organization: UniSQL, Inc. Lines: 39 In article <12844@skye.cs.ed.ac.uk>, scm@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@cs.utexas.edu UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!pckim TEL: (512)343-7297 Ext. 332 FAX: (512)343-7383