Script example of something that should work:
void main()
{
int nCount;
for (nCount = 1;GetIsObjectValid(GetNearestObjectByTag("WP_PEASANT_EXIT",OBJECT_SELF,nCount));nCount++);
// Do more things here...
}
Works with ; replaced by {} or a while loop.
For it used in Bioware's code see nw_pw_peasant9.nss in Chapter 1 and Chapter 4 of the OC.
@mtijanic asked me to log.