How to Set Conditional Breakpoints in Visual Studio 2022?

When debugging a program, a situation often arises where it is necessary to trigger a breakpoint only if the variable contains a certain value. Very often this situation arises in the loop. Let’s look at an example and learn how to put a breakpoint on a certain condition. There is a ‘persons’ array. In the loop, we go through this array and display the first and last names in the console. I set a breakpoint inside the loop, but we need the breakpoint to work only if the person’s last name is ‘Brown’. Let’s see how to do it:

Step 1 – Set Regular Breakpoint

Set breakpoint
Click to open in a new tab

Step 2 – Right Click on Breakpoint

Right click on menu
Click to open a new tab

Step 3 – Set Conditional Breakpoint

set condition in breakpoint
Click to open in a new tab.

Step 4 – Run App

conditional breakpoint example
Click to open in a new tab.

Video Demonstration

Leave a Comment