Dec

From Delphi Pascal wiki
Jump to navigation Jump to search

Decrements a variable.


Declaration
procedure Dec(var X[ ; N: Longint]);
Target
Windows, Real, Protected
Remarks
X is an ordinal-type variable or a variable of type PChar if the extended syntax is enabled, and N is an integer-type expression. X is decremented by 1, or by N if N is specified; that is, Dec(X) corresponds to X := X - 1, and Dec(X, N) corresponds to X := X - N.
Dec generates optimized code and is especially useful in a tight loop.
See Also
Inc
Pred
Succ


Sample Code

{Dec.PAS}
{Sample code for the Dec procedure.}

var
  IntVar: Integer;
  LongintVar: Longint;
begin
  Intvar := 10;
  LongintVar := 10;
  Dec(IntVar);   { IntVar := IntVar - 1 }
  Dec(LongintVar, 5);  { LongintVar := LongintVar - 5 }
end.