Try something like this for your loop
(while (not ATTr)
(if (not (and (setq ATTr (car (nentsel str)))
(member
(vla-get-objectname
(setq ATTr (vlax-ename->vla-object ATTr))
)
'("AcDbAttribute" "AcDbText")
)
)
)
(setq ATTr nil)
)
)
As long as ATTr is nil, the loop will continue to run, once there is a valid value in ATTr the loop will exit.
You will need to ensure that ATTr is always nil upon entering the loop.