Share via

Debug Goto Statement Visual Studio

Sid Kraft 41 Reputation points
2026-05-16T21:44:03.3766667+00:00

Using Visual Studio, C++ with the debugger, how does one "branch" to a particular statement in the code? Sid Kraft

Developer technologies | Visual Studio | Debugging

2 answers

Sort by: Most helpful
  1. RLWA32 52,566 Reputation points
    2026-05-16T22:03:27.47+00:00

    Have a look at the VS Debugger's ability to set the next statement to be executed Move the execution pointer to change the execution flow in the debugger

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments

  2. AI answer

    2026-05-16T21:44:14.1766667+00:00

    In C++ code running under the Visual Studio debugger, execution cannot be arbitrarily “branched” to an arbitrary source line from the debugger UI. The debugger supports:

    • Setting breakpoints on the line where execution should pause, then continuing with F5 so the program runs normally until that point.
    • Using step commands (F10, F11) to move through code one statement at a time.

    To transfer control inside the program logic itself, the C++ language provides the goto statement:

    void func()
    {
        // ... some code ...
    
        goto target;  // unconditional branch
    
        // code skipped by goto
    
    target:
        // execution continues here
    }
    

    Rules for goto in C++:

    • The label must be in the same function as the goto.
    • goto cannot jump forward over the initialization of a variable that would be in scope at the destination.
    • It is generally recommended to use break, continue, and return instead of goto when possible.

    So, to “branch” while debugging:

    • Use breakpoints and stepping in the debugger to control where execution stops and how it advances.
    • Use goto labels in the C++ code itself if an unconditional jump within a function is required by the program logic.

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.