> What if the array is empty?
Same thing -- check your input. `if' for check, `while' for loop/iterations.
Mixing the two isn't a good thing, worst optimization ever.
_____
Posted Apr 7, 2008 6:17 UTC (Mon) by man_ls (subscriber, #15091)
[Link]
It depends. Quite often it doesn't matter much, and the compact version can be better (at least it takes less time to write). You know what they say about premature optimization, don't you?
By the way, with Java your best optimization is to write while (i != 0) instead of while (i > 0), because otherwise the JVM will perform arithmetic comparisons instead of logical. (Yes, it is pitiful.) I believe they have fixed it now, but it would be nice to know for sure.
just correct loops (Problem and solution)
Posted Apr 7, 2008 8:28 UTC (Mon) by olecom (guest, #42886)
[Link]
> It depends. Quite often it doesn't matter much, and the compact version
> can be better (at least it takes less time to write).
All was about decrement-after-check access in the loop.
> You know what they say about premature optimization, don't you?
Those loops are quite fine for me, YMMV.
BTW, i'm in to system programming, so i don't know what Java is, really .:)
--
sed 'sed && sh + olecom = love' << ''
-o--=O`C
#oo'L O
<___=E M