Introduction to Breakpoints
Introduction to Breakpoints
Introduction
A breakpoint is a line in the code where you want the execution to suspend. The reason you use a breakpoint is to examine what happens in your application when execution reaches that point.
Practical Learning: Introducing Breakpoints
using static System.Console; Title = "Watts' A Loan?"; WriteLine("This application allows you to evaluate a loan."); WriteLine("To proceed, enter the following values."); WriteLine("=---------------------------------------------="); Write("Enter the principal: "); double principal = double.Parse(ReadLine()!); Write("Enter the interest rate: "); double interestRate = double.Parse(ReadLine()!); Write("Enter the number of months: "); int periods = int.Parse(ReadLine()!) / 12; double iRate = interestRate / 100; double interestAmount = principal * iRate * periods; double futureValue = principal + interestAmount; WriteLine("==============================================="); WriteLine("Loan Summary"); WriteLine("=---------------------------------------------="); WriteLine("Principal: {0:F}", principal); WriteLine("Interest Rate: {0:P}", iRate); WriteLine("Period For: {0} months", periods); WriteLine("Interest Amount: {0:F}", interestAmount); WriteLine("Future Value: {0:F}", futureValue); WriteLine("==============================================");
This application allows you to evaluate a loan. To proceed, enter the following values. =---------------------------------------------= Enter the principal: 3725.85 Enter the interest rate: 8.765 Enter the number of months: 36 =============================================== Loan Summary =---------------------------------------------= Principal: 3725.85 Interest Rate: 876.50% Period For: 36 months Interest Amount: 979.71 Future Value: 4705.56 ============================================== Press any key to close this window . . .
A breakpoint is a line (or section) of code where you want the execution to pause until you, as the developer or application tester, decide to continue. To have a breakpoint, you must create it. To create a breakpoint, first identify the line of code where you want to add it. Then:
A breakpoint is represented by a red circular button:

After creating a breakpoint, when code executes and reaches that line, it would pause and let you know by drawing a right-pointing yellow button:

Practical Learning: Creating and Using a Breakpoint

This application allows you to evaluate a loan. To proceed, enter the following values. =---------------------------------------------= Enter the principal: 6255.75 Enter the interest rate: 9.725 Enter the number of months: 48 =============================================== Loan Summary =---------------------------------------------= Principal: 6255.75 Interest Rate: 9.73% Period For: 48 months Interest Amount: 2433.49 Future Value: 8689.24 ============================================== To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .
Usually, you want to test various sections of your code for different reasons or goals. As a result, you can create as many breakpoints as you want. When debugging, the debugger would stop at each breakpoint. You can then continue when you have examined code at the selected breakpoint.
Practical Learning: Creating and Using Breakpoints

his application allows you to evaluate a loan. To proceed, enter the following values. =---------------------------------------------= Enter the principal: 18225.45 Enter the interest rate: 6.815 Enter the number of months: 60 =============================================== Loan Summary =---------------------------------------------= Principal: 18225.45 Interest Rate: 6.82% Period For: 5 months Interest Amount: 6210.32 Future Value: 24435.77 ============================================== Press any key to close this window . . .
You can combine the Step Into and/or the Step Over feature with breakpoints. That is, you can examine each code line after line until you get to a specific line. This allows you to monitor the values of variables and see their respective values up to a critical section. To do this, first create one or more breakpoints, then proceed with steps of your choice.
Practical Learning: Stepping to Breakpoints
This application allows you to evaluate a loan. To proceed, enter the following values. =---------------------------------------------= Enter the principal: 6535.85 Enter the interest rate: 7.625 Enter the number of months: 48 =============================================== Loan Summary =---------------------------------------------= Principal: 6535.85 Interest Rate: 7.62% Period For: 48 months Interest Amount: 1993.43 Future Value: 8529.28 ============================================== Press any key to close this window . . .
A Breakpoints Window
Introduction
Breakpoints are some types of objects and must be managed. For example, you can create breakpoints as we saw in previous sections. You can also delete them or create new ones in different sections of your code.
A Window for Breakpoints
To assist you in using and managing breakpoints, Microsoft Visual Studio provides a special window: The Breakpoints window. To get the Breackpoints window, you should first start a debugging operation. The Breakpoints window usually appears in the bottom (-right) section of Microsoft Visual Studio.
When in a Breakpoint-Less Session
When you start a debugging session, if there is no breakpoint in your project, a Breakpoints window would display but it would be empty:

Otherwise, if you had first created some breakpoints, their list would display in the Breakpoints window.
Managing Breakpoints
Introduction
Remember that each breakpoint shows a button in the margin of its line in the Code Editor. In the Breakpoints window, each breakpoint is represented by a row in the list:

Removing a Breakpoint
At any time, such as after using a breakpoint, you can remove it. To delete a breakpoint:


Practical Learning: Deleting a Breakpoint
Deleting all Breakpoints
Remember that you can create more than one breakpoint. If you have more than one breakpoint in your code, execution would pause at each one of them. At any time, you can remove one or all breakpoints. To delete all breakpoints, on the main menu, click Debug -> Delete all Breakpoints.
Disabling a Breakpoint
Remember that when you are debugging your code, if you had created some breakpoints, code execution would stop (or break) at each breakpoint. If you already know what is supposed to happen on a breakpoint, we saw that you can delete such a breakpoint. Sometimes, you may want to conduct a debugging operation that must ignore a certain breakpoint, in which case you don't yet want to remove such a breakpoint. In that case, you can disable a breakpoint instead of deleting it. When a breakpoint is disabled:


To disable a breakpoint:
Practical Learning: Ending the Lesson
|
|
|||
| Previous | Copyright © 2010-2026, FunctionX | Saturday 11 July 2026, 10:55 | Next |
|
|
|||