Using an Integrated Debugger: Running and Breakpoints
Vaibhav • September 11, 2025
In the last article, we explored how stepping through code helps you understand your program line by line. But stepping is only one part of the debugging toolkit. In this article, we’ll introduce two more essential features of an integrated debugger: running with breakpoints and controlling execution flow.
These tools allow you to pause your program at specific lines, inspect what’s happening, and then continue execution when you’re ready. They’re especially useful when you want to skip over code that’s working fine and focus on the parts that are causing trouble.
What is a Breakpoint?
A breakpoint is a marker you place on a line of code to tell the debugger: “Pause here.” When your program reaches that line, it stops running and gives you control. You can then inspect variables, step through code, or continue execution.
Think of breakpoints as checkpoints in your program. You don’t have to stop at every line-just the ones you care about.
int price = 100;
int tax = 18;
int discount = 10;
int subtotal = price + tax;
int finalPrice = subtotal - discount;
Console.WriteLine("Final price: " + finalPrice);
If you’re only interested in checking the value of finalPrice
, you can set a breakpoint on the line
that calculates it. The debugger will run the program normally until it hits that line, then pause so you can
inspect what’s going on.
How to Set a Breakpoint
In Visual Studio, setting a breakpoint is easy:
- Click in the left margin next to the line of code where you want to pause
- Or place your cursor on the line and press F9
A red dot will appear in the margin, and the line will be highlighted. That’s your breakpoint.
When you run the program in debug mode (by pressing F5), it will execute normally until it reaches the breakpoint. Then it will pause and give you control.
You can set as many breakpoints as you like. The debugger will stop at each one in order.
Running vs Debugging
It’s important to understand the difference between running your program and debugging it:
- Running (Ctrl + F5): The program executes from start to finish without stopping
- Debugging (F5): The program runs, but pauses at breakpoints so you can inspect it
When you’re trying to find a bug, always use the debugger. It gives you much more control and visibility.
Inspecting Variables at a Breakpoint
When your program pauses at a breakpoint, you can inspect the current state of your variables. In Visual Studio, you can:
- Hover over a variable to see its value
- Use the Locals window to see all variables in the current scope
- Add variables to the Watch window to track them across breakpoints
This is incredibly useful when you’re not sure why a variable has a certain value. Instead of guessing, you can see exactly what’s going on.
int apples = 5;
int oranges = 3;
int total = apples + oranges;
Console.WriteLine("Total fruits: " + total);
If you set a breakpoint on the line that calculates total
, you can hover over apples
and oranges
to confirm their values before the addition happens.
Continuing Execution After a Breakpoint
Once your program pauses at a breakpoint, you have several options:
- F10 (Step Over): Execute the current line and move to the next one
- F11 (Step Into): Go inside a method (we’ll use this later when methods are introduced)
- F5 (Continue): Resume execution until the next breakpoint or the end of the program
This gives you fine-grained control over how your program runs. You can pause, inspect, and continue as needed.
Disabling and Removing Breakpoints
Sometimes you want to keep a breakpoint for later, but not stop at it right now. You can disable it by:
- Right-clicking the red dot and choosing Disable Breakpoint
- Or pressing Ctrl + F9 while the line is selected
To remove a breakpoint completely, just click the red dot again or press F9 on the line.
Use breakpoints to pause at key points in your program-especially before and after calculations, input/output, or any line where a variable changes.
Using Breakpoints to Debug Input
Breakpoints are especially helpful when your program takes user input. You can pause before and after
Console.ReadLine()
to see what the user typed and how it’s being used.
Console.WriteLine("Enter your name:");
string name = Console.ReadLine();
Console.WriteLine("Hello, " + name);
Set a breakpoint on the line after ReadLine()
. When the program pauses, you can inspect the
name
variable to confirm it contains the expected value.
Breakpoints vs Console.WriteLine
You might be wondering: why use breakpoints when you can just print values with Console.WriteLine
?
Here’s the difference:
- Console.WriteLine is great for logging and tracing over time
- Breakpoints let you pause, inspect, and control execution in real time
Both are useful. In fact, many developers use them together. You might use Console.WriteLine
to log
a value, then set a breakpoint to investigate it more deeply.
Conditional Breakpoints (Preview)
While we won’t use them just yet, it’s worth knowing that breakpoints can be made smarter. You can set a conditional breakpoint that only pauses when a certain condition is true.
For example, you could pause only when price > 100
. This is helpful when debugging loops or
repeated calculations. We’ll explore this in more detail once we introduce control flow and loops.
You can view and manage all your breakpoints in Visual Studio by pressing Ctrl + Alt + B. This opens the Breakpoints window, where you can enable, disable, or delete them all at once.
Summary
Breakpoints and controlled execution are essential tools in your debugging toolkit. They let you pause your program at exactly the right moment, inspect what’s happening, and continue when you’re ready. In this article, we covered:
- What breakpoints are and how to set them
- The difference between running and debugging
- How to inspect variables at a breakpoint
- How to continue execution after pausing
- When to use breakpoints vs print statements
With breakpoints, you don’t have to guess what your code is doing-you can see it in action. In the next article, we’ll explore how to watch variables over time and use the debugger’s watch window to track changes as your program runs.