I have a loop written like so
for( i = (count>=0)?1:-1;(count>=0)?i<=count:i>=count;(count>=0)?i++:i--){
do_something_with( i )
}
As you can see I am using the ? operator 3 time in the loop initialization .
Is there any way to simplify this ?
Currently the cpu has to compute a minimum of 2 extra decisions and a max of 3 extra
for each and every iteration. I am trying to reduce this .
Ps : I am trying to avoid using if statements .
Currently I am using javascript as a language
You can do the decision once at the start of the loop, and use the
!=operator for the comparison:Demo: http://jsfiddle.net/Guffa/2Z369/