Improve all loops for better optimization

Use comparison with the zero in loop condition - this can be
implemented without additional CMP instructions.