How to redo earlier part of program

Hi all,

I can’t seem to find info on how to redo a section of code based on a variable.

I am doing some machine tending with our UR5E and programming with Polyscope as I’m still generally new to using these. Still use quite a bit of insert script but not fully writing the program that way.

Basically the robot will start with a set of user input variables, then move and seek for stock in an irregular pallet, move it to a location to locate the center of the stock based on the user input, and if the robot will check that the stock size entered is actually correct. If it detects different size stock, I am trying to have it remove the bad stock and try a second time to get a good piece of stock and then continue the rest of the program as normal.

I tried just copy and pasting the fist section of the program into an if/else statement but the item #'s changed in the pallet. Not only that, but those same Items are now in a totally different location relative to the first pallet. (which should be identical still, I’ve made no changes to the waypoints/items) Then I tried to make it a sub program which actually worked, but only for the 1st waypoint/item. The other waypoints look like they are in the same, incorrect location as with the other method. So it works for the 1st waypoint and then when it reaches the end of the sub program it just stops there. I can’t figure out how to return to the main program and I tried using “return()”.

My question is: What is the best practice for redoing earlier, identical lines of a program and then continueing?