I need a function() to keep running once a button is pressed, and keep running

I am a little new to Arduino, but I Have done a good amount of other programming. I am a ham radio operator, and I have directional antennas that I need to rotate. I have an old rotator that I am upgrading to use my arduino as a digital controller for it. I will only include the code that I believe is relevant to my issue because I know how painful it is to look through 1000 lines of someones code trying to find what is needed. What I want to do is press my "CALIBRATE" button and then let go of the button, and let my CalibrateFunction() run until one of my position switches goes to HIGH. right now, it works as long as I hold the button down. The purpose of this is to spin my rotator clockwise (CW) until one of the four position sensors is tripped(North, East, South, West) that will stop the calibration function and the rotator will stop moving. I know I will need to debounce the switch, but first I want to get the function to run after I let go of the CALIBRATE button. Here is my code

void loop() {
 
  CALVAL = digitalRead(CALIBRATE);          //Check the position of the calibrate switch and assign it to the variable
     if (CALVAL == HIGH){ 
          CalibrateFunction();
     }
}
 int CalibrateFunction(){          //Calibration Function first checks to see if one of the four calibration switches is high, and if not
                                    //sets the rotator into a clockwise motion until one of the calibration switches is switched High.
  VALN = digitalRead(N);             //Check if the position switch is high or low and assign value to variable
  VALE = digitalRead(E);              //Check if the position switch is high or low and assign value to variable
  VALS = digitalRead(S);               /Check if the position switch is high or low and assign value to variable
  VALW = digitalRead(W);            //Check if the position switch is high or low and assign value to variable

  if ((VALN != HIGH) & (VALE != HIGH) & (VALS != HIGH) & (VALW != HIGH)){              //Check if the position switch is high or low 
  digitalWrite(CW, HIGH);
  }

There is more code, but for the most part, it is not relevant to the issue. thanks in advance.
Jake
KD7VEA

You need to replace the if test with a while loop which reads all four switches and only exits when one of them goes HIGH.

I also suggest that you check the difference between & and &&. One is a bitwise test, the other a logical test. They are not generally interchangeable.

Posting ALL of a function is necessary, too. It isn't obvious that CalibrateFunction (lousy name, by the way. What is wrong with just calibrate()?) actually returns a value.

The state change detection example bears looking at, too.

Since the comment about the while() loop has addressed your actual question, I'd like to add that I think you're going to get yourself into trouble with your variable and constant naming conventions as your code gets more complex. A constant name like "N" is just too ambiguous. Better might be "switchPinNorth" or something like that. The problem will come up if you have, for example, a north switch and a north LED. How are you going to distinguish the read pin for the switch and the write pin for the LED? And what if you have a switch, an LED, and a potentiometer for dialing in sensitivity or bias. In that case, just "N" is not going to cut it. You might use: switchPinNorth, LEDPinNorth, and biasPotPinNorth, or something like that.

A minor issue to point out is that your code isn't following standard syntax and formatting for C++. For example, all-caps values like "VALN" are usually #defined constants, not variables. This won't cause you any issues until you end up with others examining your code and they get confused.