How to make a for loop run only once then stop?

I just want it to run once then stop and wait and see if I will push the push button again for it to run again.

Here’s the part of code that I want to run only once. How would I do that?

  if (ButtonMode == 1) {                // 

    for (int s = 0; s <= 20; s++){
      for (int i = 1; i <= 12; i++){
        digitalWrite(8, HIGH); 
        digitalWrite(9, LOW); 
        digitalWrite(10, HIGH); 
        digitalWrite(11, LOW);
        delay(10);
        digitalWrite(8, HIGH); 
        digitalWrite(9, LOW); 
        digitalWrite(10, LOW); 
        digitalWrite(11, HIGH);
        delay(10);
        digitalWrite(8, LOW); 
        digitalWrite(9, HIGH); 
        digitalWrite(10, LOW); 
        digitalWrite(11, HIGH);
        delay(10);
        digitalWrite(8, LOW); 
        digitalWrite(9, HIGH); 
        digitalWrite(10, HIGH); 
        digitalWrite(11, LOW);
        delay(10);

      }
    }
      delay(2000);
      for (int r = 0; r <= 15; r++){
        for (int i = 1; i <= 12; i++){
          digitalWrite(8, LOW); 
          digitalWrite(9, HIGH); 
          digitalWrite(10, HIGH); 
          digitalWrite(11, LOW);
          delay(10);
          digitalWrite(8, LOW); 
          digitalWrite(9, HIGH); 
          digitalWrite(10, LOW); 
          digitalWrite(11, HIGH);
          delay(10);
          digitalWrite(8, HIGH); 
          digitalWrite(9, LOW); 
          digitalWrite(10, LOW); 
          digitalWrite(11, HIGH);
          delay(10);
          digitalWrite(8, HIGH); 
          digitalWrite(9, LOW); 
          digitalWrite(10, HIGH); 
          digitalWrite(11, LOW);
          delay(10);
        }
      } 
    
  }

Perhaps you need a big delay at the end to allow you to get your finger off of the button. Perhaps you need to add flip/flop logic to ensure the button has been released before the loop will actuate on another button push.

Run only once? Just remove the line that starts "for (..."

gnozahs, put the code from

for (int s = 0; s <= 20; s++){
for (int i = 1; i <= 12; i++){
to
digitalWrite(11, LOW);
delay(10);
}
}

inside setup, it wil run once and then sit in loop reading the button.

Thanks got it.

Check this it might help you, i have tried this in another place and it helped me there..

#define checkPin 7   // pushButton on pin 7
int currentValue = 0;
int previousValue = 0;

while(1)
{
       currentValue = digitalRead(checkPin);
        if(currentValue != previousValue)
          if(currentValue == HIGH)
        {
        digitalWrite(8, HIGH); 
        digitalWrite(9, LOW); 
        digitalWrite(10, HIGH); 
        digitalWrite(11, LOW);
        delay(10);
        digitalWrite(8, HIGH); 
        digitalWrite(9, LOW); 
        digitalWrite(10, LOW); 
        digitalWrite(11, HIGH);
        delay(10);
        digitalWrite(8, LOW); 
        digitalWrite(9, HIGH); 
        digitalWrite(10, LOW); 
        digitalWrite(11, HIGH);
        delay(10);
        digitalWrite(8, LOW); 
        digitalWrite(9, HIGH); 
        digitalWrite(10, HIGH); 
        digitalWrite(11, LOW);
        delay(10);

      }
    }