database query and loops

Quick question, for example if you have in your controller:

@users = User.all
for user in @users
  # blah blah blah
end

what is the best and most strait forward method to find out if you
have reached the last user in @users?

Quick question, for example if you have in your controller:

@users = User.all
for user in @users

if user == @users.last
   # do something with the last user
end

# blah blah blah
end

what is the best and most strait forward method to find out if you
have reached the last user in @users?

If you don't want that check in there you could also do...

@users = User.all
last_user = @users.pop
for user in @users
  #....
end

# do something with last_user

-philip

Thank you for the fast response, I was resorting to using if
statements in my current setup and the last_user = @users.pop solution
is much cleaner and should actuolly run faster for really large
loops.