7.2 Watching a general expression
You can do this using the “watch window”. Right click the variable or expression that you want to inspect, then select “Add
Watch...”. This pops up a dialog box. Pay attention to the “Watch Type portion”, as it can enable some very useful
features.
- “Watch Expression”: this is the default. It displays the variable in the “Watches” window. This does not alter
how the code executes.
- “Break When Value Is True”: this is applicable only if you select a condition before right clicking it, or manually
edit the “Expression” part of the dialog box to be a condition. This is also called a conditional break point, as
the program pauses its execution only when the condition becomes true.
- “Break When Value Changes”: this is another kind of breakpoint that stops whenever the watched expression
changes. This kind of breakpoints is not associated with line numbers, but rather the expression being watched.
This can be very helpful if you know that some code is changing a variable incorrectly, but don’t know where
it happens.