TC said:
Why iterate? You can test it directly, without having to loop.
Why not iterate? There would have to be tens of thousands of users and
groups before there would be any perceptible impact on performance.
Also,
that code will fail with a runtime error if the specified user does not
exist.
Rightly so. Attempting to refer to a non-existant user is an error and
should be treated as such. Determining whether a user or a group exist is a
separate operation from determining whether a user is a member of a
specified group. They should be separate functions or, at the least, if they
are combined the function should return different results to distingusih
between the various possibilities - user and group exist, user is in group,
user and group exist, user is not in group, user exists, group doesn't, user
does not exist, group does.
IMHO of course!