int pinArray[] = {2,3,4,5,6}; //create variables in an array mode by assigning the pin numbers to them
int count = 0; // we created a variable count and assigned it avalue zero
int timer = 100; //we created a variable timer and assigned it a vlaue of 100

void setup()
{
for(count=0;count<5;count++) // we have shortened the length of code by using the for loop in the code.
{
pinMode(pinArray[count], OUTPUT);
}
}

void loop()

{
for(count=0;count<5;count++)
{
digitalWrite(pinArray[count], HIGH); //here too we have lessend the length of the code by using for loop so that we do not have to type the same thing repeatedly.
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
for(count=5;count>=0;count–)
{
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
}

How your circuit should look like :-

Notice here that the circuit is designed for 7 LED’s but we only require 5. So make to less connections just according to our code. Or you may change the code and make it for 7 LED’s just as the circuit.

For guys who do not want to use the for loop in the code and want to go to the basics of sequential programming i will also provide the code that do not uses for loop :-