4.9.2 Displaying Expressions

You may have noticed that the Add Watch dialog box prompts for an expression, not simply a variable name. You can add any valid combination of variables, constants, or operators as an expression for CVW to evaluate and display in the Watch window.

The advantage of evaluating expressions is that you can reduce several variables to a single value, which may be easier to interpret than the components that make it up. For example, imagine a for loop in which the ratio between two variables, var1 and var2, should remain constant. You suspect that one of these variables sometimes has the wrong value. To see when the quotient changes, without having to mentally divide two numbers, you can specify the following expression for display in the Watch window:

(var1 / var2)

You can also display Boolean expressions. For example, if the variable var is never supposed to be greater than 100 or less than 25, the following expression evaluates to 1 (TRUE) when var exceeds its limits:

(var < 25 || var > 100)