How to add limit switch?

I have a sketch that requires a limit switch on a motor driven linear actuator. In operation the actuator extends for a period of time and then must return to its original position. I tried using an if/else command but think there must be a better way.
After the return cycle is stopped by the limit switch it has to be reset for the next cycle of the program.
Any suggestions on what type of command to use? I can post my code if that helps.

I can post my code if that helps.

How are we supposed to analyze it if you don't?

I don’t know if posting your code will help, but without the code it is nearly impossible to help. Please post.

NOTE: Before you post, use the autoformat function of the IDE (CTRL-T). Also, post your code using code tags (the button that looks like </> ).