An industrial robot including a manipulator and a robot control unit, wherein the manipulator includes a plurality of joints that are moved under the control of the control unit, and the control unit includes a storage medium including program code for controlling the motions of the manipulator when executed by the control unit, wherein a plurality of locations in the surroundings of the manipulator have been defined, each of the locations being assigned a part of the program code, and the control unit is configured to automatically select which part of the program code to be executed next based on the closeness between the current position of the manipulator and the defined locations when execution of the current program part has been interrupted, and to execute the selected part of the program code upon command.