Silenced some "comparing different types"-warnings in loop conditions

Also tried to optimize loop conditions where feasible: the end/size of the list/container needs not to be checked on every iteration.