I’m blanking here. I want to grab all the users from the userbase, but then only loop through 10 of them (I’m leaving out code that would explain why I wouldn’t just grab 10 users from the db in the first place).
users = User.objects.all()
i = 0
while i < 10:
for user in users:
if user.is_active:
# do something
i += 1
This is creating an endless loop… What stupid detail am I missing?
If you want to look for 10 active users, you’re going to need to be a bit more clever.