# Re: st: Help needed to understand behavior of Mata'sincrement/decrement

 From Joseph Coveney To Statalist Subject Re: st: Help needed to understand behavior of Mata'sincrement/decrement Date Tue, 16 May 2006 15:45:36 +0900

```Thank you, Bill, for addressing the matter and for re-iterating good advice.

Believe it or not, I was not confused as to what "entire expression" means.
And the example Bill showed

: i = 1

: (i, ++i, ++i, i, i++)
1   2   3   4   5
+---------------------+
1 |  2   2   3   3   3  |
+---------------------+

is as I expected.  What threw me was

:
: i = 1

: (i, i, ++i, ++i, i, i++)
1   2   3   4   5   6
+-------------------------+
1 |  1   1   2   3   3   3  |
+-------------------------+

Regardless, the take-home message is as Bill said (and as David Harrison's
example--perhaps another manifestation of the above--reinforces):  don't do
it.

Not that I was ever advocating it.  This is a shaving-the-yak story:  I got
led there via surveying the boundaries of what "entire expression" means.

What I really wanted to do all along was to use the increment operator on a
sentinel variable--a probe--to explore the behavior of Mata's operators in
general, such as determining whether Mata does "short-circuiting" with
logical operators (below--it's probably somewhere in the user's manual,
too).  Again, the assignment-cum-comparison statement is needed there for
exploration of the language and is not just to be cute.

Joseph Coveney

:
: if (1 == 1) "do nothing";;
do nothing

: // Why are two semicolons needed?
:
: y = x = 1

: (x, y)
1   2
+---------+
1 |  1   1  |
+---------+

: if ( (1 == 1) || ((y = x++) == .) ) ;;

: (x, y)
1   2
+---------+
1 |  2   1  |
+---------+

:
: y = x = 1

: if ( (1 == 1) | ((y = x++) == .) ) ;;

: (x, y)
1   2
+---------+
1 |  2   1  |
+---------+

:
: y = x = 1

: if ( (1 != 1) && ((y = x++) == .) );;

: (x, y)
1   2
+---------+
1 |  2   1  |
+---------+

:
: y = x = 1

: if ( (1 != 1) & ((y = x++) == .) ) ;;

: (x, y)
1   2
+---------+
1 |  2   1  |
+---------+

:
: end

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```