Try using iterator protocol instead of 'is_eof'