Does assigning same value to datatype decrease efficiency?

73 views Asked by At

For example, I have an infinite while loop which keeps assigning true to our testBool:

boolean testBool;

while(true) {

    testBool = true;

    ...more logic...
} 

Are we wasting computation on reassigning the same value to our datatype, or are languages smart enough to recognize this inefficiency?

1

There are 1 answers

1
pveentjer On BEST ANSWER

A smart compiler would pull it out of the loop.

https://en.wikipedia.org/wiki/Loop-invariant_code_motion