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;
You can use exceptions.
Call an Abort in inner if or loop, and catch EAbort exception where u want to continue
UPD. Someone just upvoted this. Seems the topic is not burried dead long ago.
Ok, then giving a quick summary of what was burried in comments here and there.
This approach may be inferior to Marjan’s try-exit-finally one, see his answer: https://stackoverflow.com/a/11689392/976391
Exceptions are somewhat less expensive in Delphi, Borland held few patents on this, but still
finallymight be executing faster, thanraise+except.OTOH, this approach can be generalized to have several nested exitable if-blocks and different exit targets, due to exceptions cancelling and different classed can be used.
And i feel the code a bit cleaner, better expressing developer’s (topic starter’s) train of thought, when except-block is just an exit anchor, and the real code is after it, not inside it (as would be required for finally-solution).
This generalization, though, tends to quickly mutate into spaghetti too, just another kind of it.
Granted, the very problem seems nasty an is calling for refactoring of the whole piece. Without refactoring all the solutions would be messy one way or another. If ladders, plain old
goto, flag vars – choose your poison. We can argue to death which one is less ugly, but ugly they all are.