Help running syntax one in every loop

Good day everyone, I'm having a problem with having a syntax run once, then reset itself and run again as the loop starts over. Its a stepper motor, so when it reached the top of the wall, it should come down and then go up and so on. i've used a IR prox sensor to sense when it reaches the top of the wall, and a limit switch for when the stepper reached the end while coming down. For the given code i used the variable stopz to move between loops. The problem is i want it to run once, to incriment the value, move on and decriment, and then reset the value so it can do the same action over again. The problem with the given code is that the variable stopz keeps adding, it doesn't stop when just adding 1. I tried for(;;), while(1), but it doesn't reset so that it can do the same again. any help would be greatly appreciated.

void loop() {

  topwall = sharp.distance();
  limitsw_val = digitalRead(limit_switch);
  // Serial.println(topwall);

  if (topwall <= twalldist && stopz == 0)
  {

    rotate(-1000, .25); //up
    digitalWrite(sprayer, HIGH);

  }
  else if (topwall > twalldist)
  {

    stopz = stopz + 1;
    Serial.print("Up =");
    Serial.print(stopz);


  }

  else if (stopz == 1 && limitsw_val == 1)
  {

    rotate(1000, .25); //down
    digitalWrite(sprayer, HIGH);
  }

  else if (stopz == 1 && limitsw_val == 0)
  {


    stopz = stopz - 1;
    Serial.print("Down =");
    Serial.print(stopz);

  }

}

SUCCESS!! ended up using this

stopz = constrain(stopz,0,1);