Why won't it stop???

I have made this programming but I want all pins to be LOW in the if statement.What have I made wrong?

int timer = 100;
const int ledPins[] = {
2, 7, 4, 6, 5, 3 };

int pinCount = 6;

const int analogPin = 0;
const int threshold = 400;

void setup() {
int thisPin;
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);

}
}

void loop() {
int analogValue = analogRead(analogPin);

if (analogValue > threshold) {
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
digitalWrite(ledPins[thisPin], LOW);
}
}
else {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
}

// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}

Thanks

Why do some of your loops increment and some decrement? There does not seem to be a reason to set all the pins LOW in any particular order.

If the analog value is less than threshold, and we don't know that it is, you turn each pin on, then off. If the analog value is greater than threshold, you turn all the pins off.

Then, you turn all the pins on, one at a time, for 1/10 of a second, then off.

What do you actually see happening? How does that differ from what you expect?

Try commenting out that whole final loop. Does the program then behave as you expect?