Making LEDs work in reverse

Hi I am trying to figure out how I can do make the LEDs go from left to right then once it reaches the end, go from right to left in the same way.

Here is my code!!

const int buttonpin = 7;
int ledpin[4] = { 6,9,10,11 };
int ledcount = 4;
int currentPin = 0;

void setup()
{
for (int i=0; i< ledcount; i++) pinMode(ledpin*, OUTPUT);*
_ for (int i=0; i< ledcount; i++) digitalWrite(ledpin*, LOW);_
_
}_
void loop()
_
{_
_
if (digitalRead(buttonpin) == HIGH) // assuming buttonpress => low → high*_
* {*
* digitalWrite(ledpin[currentPin], LOW);*
* currentPin = (currentPin + 1) % ledcount; // wraps ledpin around*
* digitalWrite(ledpin[currentPin], HIGH);*
* }*
* delay(100);*
}

See the italics? That is why we ask people to post ther Cody using code tags, see the how to use this forum sticky.

As to your question there are lots of ways. Have a Boolean variable that is true when counting up and false when counting down. Then use it in an if statement to see if you need to increment or decrement your count.
Then if the count is outside your limits toggle this variable.

Thanks for the advice. I tried what you advised, but the LED seems to remain in one position. Quite stuck to be honest.

#define NUM_LEDS 4

const uint8_t PIN_BUTTON = 7;
const uint8_t PIN_LEDS[NUM_LEDS] = { 6, 9, 10, 11 };

uint8_t currentPin = 0; 
int8_t nextStep = 1;

void setup()
{
    for (uint8_t i=0; i != NUM_LEDS; ++i)
        pinMode(PIN_LEDS[i], OUTPUT);
}

void loop()
{
    if (digitalRead(PIN_BUTTON) == HIGH)  // assuming buttonpress => low -> high
    {
        digitalWrite(PIN_LEDS[currentPin], LOW);
        currentPin += nextStep;
        if (currentPin == 0 || currentPin == (NUM_LEDS - 1))
            nextStep *= -1;
        digitalWrite(PIN_LEDS[currentPin], HIGH);
    }
    delay(100);
}

Thanks for the suggestions

What if I wanted to add a tilt switch to reset the value back to 0?

Ecya87: What if I wanted to add a tilt switch to reset the value back to 0?

Test for the switch press with an if statement and then reset both the count and inceremnt.

Ecya87: Thanks for the advice. I tried what you advised, but the LED seems to remain in one position. Quite stuck to be honest.

Then you didn't do all of what I said.