A very useful and cool feature in Delphi 2009 is the Exit keyword. Yes, it’s that Exit that “returns” from a function call. So what’s so exiting about it? Nothing really – for people coming from C-like languages, but for Delphi people it’s the fact that you can now write this:
function f1(x : Integer) : Integer
begin
if (x < 0)
Exit(-1);
Exit(x * x);
end;
[/sourcecode]
instead of:
[sourcecode language='delphi']
function f1(x : Integer) : Integer
begin
if (x < 0)
begin Result := -1; Exit; end;
Result := x * x;
end;
[/sourcecode]
Well maybe it wasn't the best example of it's use but you surely found so many cases when you needed to write something like begin Result := ....; Exit; End; - Exit will be very useful in those cases.