Best idiom for a decrementing loop

java

Solution

I recommend the following because comparison against zero is optimized at the byte code level.

for(int idx=(len-1); idx>=0; idx--) {...}

This is a suggestion from Java Performance Tuning by Jack Shirazi

Problem

What's the best/preferred idiom for a decrementing for loop, and why? ``` for(int idx=(len-1); idx>=0; idx--) {...} ``` or ``` for(int idx=(len-1); idx>-1; idx--) {...} ``` or (based on sylvarking's answer, but using for to constrain the index scope) ``` for(int idx=len; idx-->0; ) {...} ``` Is one or the other more likely to trip up another developer?

Original source