Name

Exit Procedure

Syntax

Exit;

Description

Call the Exit procedure to return immediately from a function or procedure. If you call Exit from within a try-finally block, the finally parts runs before the subroutine returns.

The Exit procedure is built into the compiler and is not a real procedure. If you call Exit outside of a subroutine or method, Delphi exits the application.

Example

// Compute the number of iterations at the point (X, Y).
// Stop at MaxIterations, which is a crude approximation of infinity.
// This function is used in the BeginThread example.
function ComputeIterations(X, Y: Double): Integer;
const
  Threshold = 4.0;
var
  XNew, YNew: Double;
  XC, YC: Double;
begin
  XC := X;
  YC := Y;
  for Result := 0 to MaxIterations-1 do
  begin
    XNew := X * X - Y * Y + XC;
    YNew := 2 * X * Y + YC;
    if (XNew * XNew + YNew * YNew) > Threshold then
      Exit;
    X := XNew;
    Y := YNew;
  end;
  Result := MaxIterations;
end;

See Also

Break Procedure, Goto Keyword, Try Keyword

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.