More portable loop code