Thursday, May 10, 2012

Incremental and Decremental operators in .NET and JavaScripts

Some things are easiest to learn.. but hard to recollect with spontaneity, if we are asked to.
Incremental and Decremental operators fall in the same category, may be even for experienced programmers.

To avoid confusions, I am herewith writing a simple scenario.
Note, Incremental and Decremental operators are having same behavior in .NET and JavaScript.


i= 1 //Initial value assignment.
i++= 1 //This is, post-incremental; it will first return and than increment.
i= 2 //i was incremented by 1 during above statement.
++i= 3 //This is, pre-incremental; it will first increment and than return.
i= 3 //i was incremented by 1 during above statement.
i+=1= 4 //same as ++i.
i= 4 //i was incremented by 1 during above statement.
i--= 4 //This is, post-decremental; it will first return and than decrement.
i= 3 //i was decremented by 1 during above statement.
--i= 2 // This is, pre-decreemental; it will first decrement and than return.
i= 2 //i was decremented by 1 during above statement.
i-=1= 1 //same as --i.
i= 1 //i was decremented by 1 during above statement.

No comments:

Post a Comment

Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.

Thanks
Nirman