Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a local variable is used instead of var parameter in a procedure?

Tags:

oIn Delphi SysUtils is a ScanBlanks procedure:

procedure ScanBlanks(const S: string; var Pos: Integer);
var
  I: Integer;
begin
  I := Pos;
  while (I <= Length(S)) and (S[I] = ' ') do Inc(I);
  Pos := I;
end;

I wonder why the procedure is using I variable. Can't we use use Pos var directly?

procedure ScanBlanks(const S: string; var Pos: Integer);
begin
  while (Pos <= Length(S)) and (S[Pos] = ' ') do Inc(Pos);
end;

Is it because of some speed/memory penalty? Can someone more experienced explain me the reason/difference?