i just found the response in this article:
http://introcs.cs.princeton.edu/java/11precedence/
for(int i=0; i<5;)
i = i++;
}
it is a post-increment operator so the Associativity is Left-To-Right.
i++ in it's left has an the operator = .
Cause of Associativity ( and not the level of Precedence ) i assign the value of the i in the right to the variable i in the left. After doing this i do the increment but it doest have a reference variable whent o go for the moment so it remain in the memory for the next row of code that will call the i variable.
Precedence of operator:
hightl level of precedence is ++
lower level of precedence is =
Associativity of the operator:
Left to Right for the operator ++
Right to left for the operator =
So:
java will read all the line with the text till when java will found the semicolon (;). After finding a semicolon (;) java will call this a statement and will go for first to understand the operator and the variable that has inside.
Java see that it has 2 operators , one is ++ and the other one is =.
Cause of precedence the operator ++ will decide the associativity.
So the operator ++ has the associativity from Left to Right.
So:
i++ (Left to Right) ----------------> (execute everything before i for first)
++1 ( Right to Left ) <--------------- (execute everything after i for first)
i++ will calculate first what will be in the left and later it will go in the right.
- i++ will execute everything in the left first (.. i)++ till i
found another operator with hight precedenze that will change the
direction of the flow cause of level precedence.
- The next operator is = and it is with lower level of precedence so i
will execute what the operator ++ was saying. For this reason i
valutate ( i = i ).
- After assign the ( i = i ) i dont have other operator and i will
turn back the controlo to the operator ++ so i will execute the
remain. For this reason i increment of 1 value the i variable.