on a side note, personally, i tend to write code more like this: function FindFirstMatch (const List: TItemList; const Status: TItemStatus; var aPosition:integer):boolean;
this way, you dont have 'magic numbers' (ie -1) in the same variable as your position indicator.. it also means the function is easier to use, eg: if FindFirstMatch (List,Status,aPosition) then begin //do stuff with aPosition to protect your code even more, i'd put assertions in to clarify what inputs you expect. eg Assert(List<>nil) and i'd explicitly declare the inputs as var or const (as above) so that its obvious that some vars wont be changed. if you havent already, try reading a book called "Code Complete", it discusses a lot of stuff like this.. btw in terms of the actual question, i don't have a problem with either approach. probably prefer the first, shorter approach. tho its a valid arguement that keeping the loop var seperate from the result var is more 'correct'. --- Stephen Bertram <[EMAIL PROTECTED]> wrote: > 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 > __________________________________________________ Do you Yahoo!? HotJobs - Search new jobs daily now http://hotjobs.yahoo.com/ --------------------------------------------------------------------------- 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/