Repeat same command 10 times, searching for a element before pressing ok

It appears that if the element is there, it still goes and presses the OK button. I need it to check if the “other possible” portion of the element exists, as sometimes it can say 2,5,7,10,20, basically any number of matches could be found, and if it doesn’t exist, press OK, then move onto the next one.