Best control structure for task of aligning motor with sensor

Well, you've written a move clockwise function which also does the tests....

Remember I suggested split it up... ?

your main loop could discover when to move clockwise or anti-clockwise ( or not at all ) as per dave-in-nj's suggestions.

Then write 'move_clockwise' AND 'move_anticlockwise functions' , and call them as appropriate.

Or a function 'move' , and invoke it with a variable with values clockwise or anticlockwise, and have the function itself implement this.

that's 2 of the 100 ways to skin this cat...!

regards

Allan