12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Us<strong>in</strong>g the Debugger<br />

Conditional Breakpo<strong>in</strong>ts<br />

NOTE<br />

NOTE<br />

In the case of a conditional breakpo<strong>in</strong>t, program execution is paused only when predef<strong>in</strong>ed<br />

conditions are met. To create a conditional breakpo<strong>in</strong>t, first set the breakpo<strong>in</strong>t <strong>in</strong> the Code<br />

Editor. Then choose View | Breakpo<strong>in</strong>ts from the ma<strong>in</strong> menu to display the Breakpo<strong>in</strong>t list<br />

dialog box. Right-click on the breakpo<strong>in</strong>t for which you want to set conditions and choose<br />

Properties from the speed menu. When the Edit breakpo<strong>in</strong>t dialog box is displayed, set the<br />

conditions for the breakpo<strong>in</strong>t.<br />

Conditional breakpo<strong>in</strong>ts come <strong>in</strong> two flavors. The first type is a conditional expression<br />

breakpo<strong>in</strong>t. Enter the conditional expression <strong>in</strong> the Condition field of the Edit breakpo<strong>in</strong>t<br />

dialog box (refer to Figure 11.3). When the program runs, the conditional expression is<br />

evaluated each time the breakpo<strong>in</strong>t is encountered. When the conditional expression<br />

evaluates to true, program execution is halted. If the condition does not evaluate to true, the<br />

breakpo<strong>in</strong>t is ignored. For example, look back at the last breakpo<strong>in</strong>t <strong>in</strong> the Breakpo<strong>in</strong>t list<br />

w<strong>in</strong>dow shown <strong>in</strong> Figure 11.2. This breakpo<strong>in</strong>t has a conditional expression of x > 10. If at<br />

some po<strong>in</strong>t <strong>in</strong> the execution of the program x is greater than 10, the program will stop at the<br />

breakpo<strong>in</strong>t. If x is never greater than 10, program execution will not stop at the breakpo<strong>in</strong>t.<br />

The other type of conditional breakpo<strong>in</strong>t is the pass count breakpo<strong>in</strong>t. With a pass count<br />

breakpo<strong>in</strong>t, program execution is paused only after the breakpo<strong>in</strong>t is encountered the<br />

specified number of times. To specify a pass count breakpo<strong>in</strong>t, edit the breakpo<strong>in</strong>t and specify<br />

a value for the Pass count field <strong>in</strong> the Edit breakpo<strong>in</strong>t dialog box. Figure 11.2 shows a<br />

breakpo<strong>in</strong>t that has the pass count set to 3. Program execution will stop at this breakpo<strong>in</strong>t<br />

the third time the breakpo<strong>in</strong>t is encountered.<br />

The pass count is 1 based and not 0 based. As <strong>in</strong>dicated <strong>in</strong> the previous<br />

example, a pass count of 3 means that the breakpo<strong>in</strong>t will be valid the<br />

third time the breakpo<strong>in</strong>t is encountered by the program.<br />

Use pass count breakpo<strong>in</strong>ts when you need your program to execute through a breakpo<strong>in</strong>t<br />

a certa<strong>in</strong> number of times before you break to <strong>in</strong>spect variables, step through code, or<br />

someth<strong>in</strong>g similar.<br />

Conditional breakpo<strong>in</strong>ts will slow down the normal execution of the<br />

program because the conditions need to be evaluated each time a<br />

conditional breakpo<strong>in</strong>t is encountered. If your program is act<strong>in</strong>g sluggish<br />

dur<strong>in</strong>g debugg<strong>in</strong>g, check your breakpo<strong>in</strong>ts <strong>in</strong> the breakpo<strong>in</strong>t list and see<br />

whether you have conditional breakpo<strong>in</strong>ts that you have forgotten about.<br />

401<br />

11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!