Instead of skipping the not allowed groups, you could skip the groups, that are different than the allowed groups.
3,4,6 are mods, admins etc. X and Y are the ID's of the groups that should be visible.
if (!is_member(array(3,4,6,X,Y), $account['uid'])) continue;
3,4,6 are mods, admins etc. X and Y are the ID's of the groups that should be visible.