you can exit a while loop with break.
How to exit from an if .
Is there a kind of GOTO in Delphi ?
procedure ...
begin
if .... then
begin
here the code to execute
if (I want to exit = TRUE) then
break or GOTO
here the code not to execute if has exited
end;
here the code to execute
end;
Like Piskvor mentioned
, use nested if statement:
procedure Something;
begin
if IWantToEnterHere then
begin
// here the code to execute
if not IWantToExit then
// here the code not to execute if has exited
end;
// here the code to execute
end;
I am not in favour of using Exit's this way, but you asked for it...
Like @mrabat suggested in a comment to @Arioch 'The answer, you could use the fact that a finally block is always executed, regardless of Exit's and exceptions, to your advantage here:
procedure ...
begin
if Cond1 then
try
// Code to execute
if Cond2 then
Exit;
// Code NOT to execute if Cond2 is true
finally
// Code to execute even when Exit was called
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With