java - Basic Incrementation -


i know basic question but.

i understand concept behind. n++, ++n, n--, --n. however

public static void main(string[] args){      int count = 1;     for(int =1;i<=10;++i){      count = count * i;     system.out.print(count);     } } 

so print: 1 2 3 4 5 6 7 8 9 10.

my question is. why if incremented ++i isnt treated 2, instead of 1. inst point of ++i, increment before it's manipulated operation?

is point of ++i, increment before it's manipulated operation?

the difference between ++i , i++ matters when it's used part of bigger expression, e.g.

int j = ++i; // increment use new value assignment int k = i++; // increment, use old value assignment 

in case operation occurs @ end of each iteration of loop, on own. loop equivalent to:

int count = 1; // introduce new scope i, loop {     // declaration , initialization     int = 1;     // condition     while (i <= 10) {         count = count * i;         system.out.print(count);          // comes final expression in loop "header"         ++i;     } } 

now changing ++i i++ @ end there isn't going make difference @ - value of expression isn't used anything.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -