iStart := 0 or 100 or what ever you like
iEnd :=100 or 0 or what ever you like
iInc := -1 or 1

x := iStart

While x <> iEnd
begin
    DO YOUR STUFF
    x := x + iInc;
end;


Syntax not checked cos Delphi is not installed.

I would put the start, end and inc variables assignments in case
statement too.

Chrissy.


----- Original Message ----- 
From: "David Brennan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "NZ Borland Developers Group - Delphi List" <[EMAIL 
PROTECTED]>
Sent: Saturday, March 20, 2004 6:02 PM
Subject: RE: [DUG] Multiple "FOR" loops


> Messagefor i := 0 to 100 do begin
>   if FirstToLast then begin
>     x := i;
>   end
>   else begin
>     x := 100 - i;
>   end;
>   // DO YOUR STUFF WITH X
> end;
> 
>   -----Original Message-----
>   From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Jeremy Coulter
>   Sent: Saturday, 20 March 2004 5:43 PM
>   To: [EMAIL PROTECTED]
>   Subject: [DUG] Multiple "FOR" loops
> 
> 
>   Hi All.
>   I want to be able to specify the direction of a FOR loop.
> 
>   i.e. if the type is FirstToLast then it will be for x:=0 to 100
>   i.e. if the type is LastToFirst then it will be for x:=100 downto 0
> 
>   Basically I want to be able to go :-
> 
>   CASE Direction of
>       0: for x:=0 to 100
>       1: for x:=100 to 0
>   END;
> 
>   Begin
>     //for loop stuff here
>   End;
> 
>   But of course this is not valid.
> 
>   I then thought I should use a WHILE LOOP  but the problem here is that
> even if I define the start and stop positions, it doesnt really herlp, i.e.
> 
>   While  iStartPos <= iStopPos do
> 
>   IF iStop=100 and iStart=1 its fine, BUT if iStop is 1 and iStart=100 then
> it will not work.
> 
>   Anyone got any bright ideas? I REALLY dont want to make 2 "FOR" loops.
> 
>   Cheers,
> 
>   Jeremy Coulter
> 
> 
>   ------------------------------------------------------------------------
>   All email scanned with Nortons Antivirus 2003
>   ------------------------------------------------------------------------
> 
> 


--------------------------------------------------------------------------------


> _______________________________________________
> Delphi mailing list
> [EMAIL PROTECTED]
> http://ns3.123.co.nz/mailman/listinfo/delphi
> 
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to