I cant get the program to loop

for some reason the program stops looping after turning the leds off in sequence.

int ledArray = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int delayTime = 200;

void setup() {
//initalise ledArray as outputs
for (int i; i < 10; i++)
pinMode(ledArray[i], OUTPUT);

void loop() {
// turn leds on from 2-10.
for (int i; i <= 10; i++)
digitalWrite(ledArray[i], HIGH);
// turn leds off from 10-2.
for (int i = 10; i >= 0; i--)
digitalWrite(ledArray[i], LOW);

That's a lot of LEDs to run off an Arduino.

What is the initial value of i in your loops?

Check out this post on for loops:
for - Arduino Reference


Please remember to use code tags when posting code

Insert Serial.println(i); at POI to see what happens.

Double oops

OOPS² :nerd_face:

The value of I increments starting at 0, 0 location pertains to location 0 which is 2, then 3, and so on to 11.

Have another guess


Compare your for loop to the for loop page that I sent you. There is a difference and it is at least part of your problem


the initial value defaults to position 0 and in position 0 is output 2 according to int ledArray {2,3,4,5,6,7,8,9,10};
2=4 and so on.

All right, you've told me what you think it is but the mistake is still in your code.
To find it look very closely at the initializer portions of all three of your for loops.

how exactly does this oopsie daisy help in formatting a conclusion to the issue.

Try not to get frustrated. Focus on your issue.
To be fair it's been pointed out by multiple users in multiple ways.
It's just a couple easy to make mistakes

We have to have a little fun :wink:

for (int i; i <= 10; i++)

What have you instructed the compiler the starting value of i will be ?


thanks i found it the 0 missing in for (int i = 0; i <= 10; i++).

Ithought i defults to 0 by itself.

How many elements in your above array ?

for (int i = 0; i <= 10; i++)
digitalWrite(ledArray[i], HIGH);

How many elements are you accessing above ?

i am accessing 10

for (int i = 0; i <= 10; i++)

0 1 2 3 4 5 6 7 8 9 10


11 ?

Ordinal vs Cardinal
If you start with 0 you have to stop *** before *** the length of the container.
You currently go one step too far.
Change your comparison to <