How to repeat a set of instructions a fixed number of times

Hi everyone,
I just started using Arduino, so my question is very basic, I apologize in advance.

Short version: How can I repeat an on/off loop 120 times?

Long version: I want to create a loop that waits 8 sec to turn on a pump (off 8 sec), then turns it on for 4 sec (on 4 sec). I want to repeat this off/on loop 120 times and then turn it off for 7200 sec (off 7200 sec). Once the loop is finished I want it to start from the beginning.

This is the code I have so far:

//Code setup

void setup() {

Serial.begin(9600);
pinMode(InPut1,OUTPUT);

}

void loop() {

digitalWrite(InPut1,HIGH);//Code to turn off (yes, HIGH is off)

delay(8000); //8 sec

digitalWrite(InPut1,LOW);//Code to turn on

delay(4000); //4 sec

digitalWrite(InPut1,HIGH);//Code to turn off

delay(7200000); //2 h or 7200 sec

}

I could write 120 times, but it would not be very efficient. I would appreciate any guidance!

Thanks

Welcome to the forums. Please read the sticky post at the top to learn how to use code tags when posting your code. It will help people help you.

As for looping, the most common way would be to use a for() loop. Reference

For repeating things a fixed number of times, the usual solution is a ‘for’ loop:

  for (int i=0; i < NumberOfTimes; i++)
  {
    // The stuff to repeat
  }

The ‘for’ loop is an easy-to-read shortcut for:

  int i=0;
  while (i < NumberOfTimes)
  {
    // The stuff to repeat
    i++;
  }

Note: The value starts at 0 and ends at N-1, just like the indexes of an array of size N.