Title: Message
Pick and choose, the first option is faster, no unnecessary assignments.
 
lets face it, exit or break are both exit controls. In a small controled and encapsulated procedure such as this the exit method I feel is more practical and easier to understand. Go with what feels comfortable. there is nothing wrong with either option
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Stephen Bertram
Sent: Thursday, 31 October 2002 5:27 p.m.
To: Multiple recipients of list delphi
Subject: [DUG]: Style question - your votes please

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

Reply via email to