post increment - Difference between i++ and ++i in a loop? -


What is the difference between ++ i and i ++ for loop ? Is this a syntax thing?

A ++ is known as Postfix. <

Add 1, returns the old value.

++ A is known as prefix.

Add one to 1, returns a new value.

C #:

  string [] items = {"a", "b", "c", "d"}; Int i = 0; Foreign objects (string items in items) {Console.WriteLine (++ i); } Console. "Line" (""); I = 0; Foreign objects (string items in items) {Console.WriteLine (i ++); }  

Output:

  1 2 3 4 0 1 2 3  

foreach And while depending on the length of which you use the pay scale, it does not make any difference to the loops as you like because you: i:

0 1 2 3 4
0 1 2 3 4

If you use the value below, then clear This should be important in the form that the growing type is used:

  int n = 0; For (int i = 0; i <5; n = i ++) {}  

Comments