In theory, currentPrice is read twice. Once for comparison, once for appointment.
In practice, the compiler can cache variable access. I don't know about C #, but in C ++ on x86:
MOV AX, [currentPrice] MOV BX, 100 ;cache the immediate CMP AX, BX JLE $1 ;if(currentPrice > 100){ MOV AX, BX $1: ;} MOV [BP+price], AX ;price is on the stack.
The same loading optimization is once performed in Java bytecode unless currentPrice is declared mutable.
So, theoretically, this can happen. In practice, on most platforms this will not happen, but you cannot count on it.
John dvorak
source share