Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:28:53+00:00 2026-06-08T11:28:53+00:00

you can exit a while loop with break . How to exit from an

  • 0

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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:28:54+00:00Added an answer on June 8, 2026 at 11:28 am

    You can use exceptions.

    Call an Abort in inner if or loop, and catch EAbort exception where u want to continue

    procedure ...
    begin
    
     try 
      if .... then
        begin
    
          (*      here the code to execute  *)
    
          if I_want-to-exit then Abort;
    
          (*      here the code not to execute if has exited *)
    
        end;
      
       except on E: EABORT do ;
       end;
    
       (*  here the code to execute *)
    end;
    

    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 finally might be executing faster, than raise+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).

    type EExitException1 = class(Exception) end;
    type EExitException2 = class(Exception) end;
    procedure ...
    begin
    
     try 
      if .... then
        begin
    
          (*      here the code to execute  *)
           try
             if .... then
             begin
    
                (*      here the nested code to execute  *)
    
    
                if I_want-to-exit then raise EExitException1.Create();
    
                (** ...  **)
                if I_want-to-exit-far-away then raise EExitException2.Create();
    
                (*      here the code not to execute if if-block cancelled *)
    
             end; // if
    
           (*      here the code to execute  *)  
    
           if I_want-to-exit-outer-if-here then raise EExitException2.Create();
    
            (*      here the code not to execute  *)  
    
           except on E: EExitException1 do ; end; // killing the exception
               
           (*      here the code to execute after the outer if-block exit *)
    
        end;
    
       (* one more piece of skippable code *)
      
       except on E: EExitException2 do ; end;
    
       (*  here the code to execute yet again *)
    end;
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So the example from the wiki has phantom.exit() in two places here. Why can't
My while loop does not exit when Ctrl+C is pressed. It seemingly ignores my
I have the following code in a loop: while true: # Define shell_command p1
You can see my posted code here . My original problem was more or
In vim, type :sh will switch to shell, and exit can exit the shell
i know that in vb.net you can just do Exit Sub but i would
How can I start a job on a *nix system that will not exit
Can anyone tell me? What is the difference between exit(0) and exit(1) in C
What are the default values that can be passed to Environment.Exit method and what
In c# you can return an integer to the underlying caller using Environment.Exit(n) (which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.