Article View: comp.lang.pascal.borland
Article #192Re: N-level nested loops
From: KlausL
Date: Sun, 26 Mar 2000 00:00
Date: Sun, 26 Mar 2000 00:00
56 lines
1661 bytes
1661 bytes
Alec Soroudi wrote in message ...
> Hi, I am wondering if anyone knows of a way to make an n-level nested
>for loop.
>
>ie: for ...
> for ..
> .
> .n times
> .
> endfor
> endfor
>
>or of a way to simulate it.
>
>the level of nesting (n) is not known until run time.
>
>Thanks alot.
>
>Alec Soroudi
>
Alec,
You write a recursive routine, that is a routine that
calls itself.
Example: Add up all the numbers from 1 to 300:
Program Recursive;
var sum, x: word;
{ --------------------------------------------}
Procedure add(xx: word; var s: word);
Begin
s:= s+xx;
dec(xx);
if xx>0
then add(xx, s);
end;
{ Main program) }
Begin
sum := 0;
x := 300; { for example }
add(x, sum);
writeln ('The sum is ', sum);
end.
You need to make sure that the routine does not continue
forever. You must also make your stack sufficiently large.
KlausL
P.S. Please do not multi-post. It wastes everybody's time.
Technical Details
Message-ID:
<38dd65e1@news.internex.net.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<EQcD4.72342$Hq3.1823748@news2.rdc1.on.home.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,d844acbe9264f761 X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,d844acbe9264f761 X-Google-Attributes: gid108ebd,public From: "KlausL" <NotReceivingFEL.Consulting@attglobal.net> Subject: Re: N-level nested loops Date: 2000/03/26 Message-ID: <38dd65e1@news.internex.net.au> X-Deja-AN: 602418640 References: <EQcD4.72342$Hq3.1823748@news2.rdc1.on.home.com> X-Trace: 26 Mar 2000 11:20:33 +1000, 203.21.126.85 Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3