FWIW, I would always write it the first way. The second is just nuts.

> We're having a quiet (NOT) discussion about the PCness of the following code:
>
> function FindFirstMatch (List: TItemList; Status: TItemStatus): Integer;
> begin
>   for Result := 0 to List.Count - 1 do
>     if List[Result].Status = Status then
>       Exit;
>   Result := -1;
> end;
>
> The main objection is the use of Exit, but the only simple way I can see to write 
>around that is to add a local variable:
>
> function FindFirstMatch (List: TItemList; Status: TItemStatus): Integer;
> var
>   i: Integer;
> begin
>   Result := -1;
>   for i := 0 to List.Count - 1 do
>     if List[Result].Status = Status then
>     begin
>       Result:= i;
>       Break;
>     end;
> end;
>
> Which is preferable or what is a tidier method?
>
> Stephen
>


cheers,
peter

===========================================
Peter Hyde, SPIS Ltd, Christchurch, New Zealand
* TCompress/TCompLHA component sets for Delphi/Kylix/C++
* TurboNote+: http://TurboPress.com/tbnote.htm
  -- top-rated onscreen sticky notes
* Web automation for online periodicals: http://TurboPress.com
Find all the above and MORE at http://spis.co.nz


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to