Programmers debug code often uses breakpoints, but many people may not have used conditional breakpoints, so when will need to use conditional breakpoints.
1, for loop comparison more times, want to let the For loop stop at the specified number of loops at the
2, you want to run at the same time the code environment on their own debugging, but also does not affect the access of others
At this time you can choose to use conditional breakpoints, conditional breakpoints, as the name implies is to meet certain conditions, the breakpoint will be enabled.
The following is an example of eclipse, which details how to set a conditional breakpoint: 1. Sample code:
Class person{public
String firstName;
Public String lastName;
public int age;
Public person (string firstName, string lastName, int age) {
this.firstname = firstName;
This.lastname = LastName;
This.age = age;
}
}
public class test11{public
static void Main (String args[]) {person
people[] = new person[]{
new Person ("T Ed "," Neward "," a "," New Person "
(" Charlotte "," Neward "," a "),
New Person (" Michael "," Neward ",),
new Person ("Matthew", "Neward",)
};
for (person p:people) {
System.out.println (p);}}}
2, Breakpoint set:
2.1 hit a breakpoint inside the for loop, then right click on the breakpoint, click on the bottom of the pop-up "Breakpoint Properties"
2.2 as shown in the following figure, select Conditional, when the default suspend when True the radio button is selected, that is, when the condition is true, the breakpoint will stop
2.3 In the bottom of the blank as input conditions conditional, can be as convenient as writing Java code, as well as the hint message:
3, breakpoint debugging
After entering the condition, click the Save button to save the then you can start the debug code as usual, only your breakpoint will stop when the condition is satisfied, like the following, look at the console below, the first condition of the data has been printed out, parked in the p.age=13 record, is not very convenient. Now use it. The conditional expression of a conditional breakpoint also supports complex combinations, just as an expression that writes an if () condition in code.