Revert "simplified loop condition"

This reverts commit b284a2d194cc990cf5d9366e48eb7d674946db2e.