O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Postfix and Prefix Increment and Decrement Operators

Conceptually closely related to compound assignment with the + and - binary operators are the postfix and prefix increment and decrement operators. In essence, they abbreviate simple operators as “plus one” and “minus one” into succinct syntax, respectively as ++ and --. One common use can be found in the context of for loops, which are discussed in the Chapter 7, “Simple Control Flow.” Here is the typical pattern to create a loop that will execute the loop body 10 times:

for (int i = 0; i < 10; i++){    // Use integer value i if desired.}

A for loop consists of four parts: an initializer (here int i = 0), a condition (i < 10), an iterator (i++), and a loop body (the part in between curly braces). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required