uno output erratic even with simple for loop output test

I was having trouble with inputs and outputs on a new UNO connected to an 8 relay board, so I decided to create a simple sketch to test digital 0-13 as outputs, and strange outputs occur after the first run on the For loop, and then instead of just repeating, it does some crazy outputs (sometimes several at one time) and it takes several minutes before the For loop repeats my code again.

Is this UNO troubled or my code?

void setup() {
  for (int i=0; i<=13; i++) pinMode (i, OUTPUT);
  for (int i=0; i<=13; i++) digitalWrite(i, HIGH);  //Initialize all relays off (HIGH is off)

}

void loop() {
 for (int i=0; 1<=13; i++){
  digitalWrite (i, LOW);
  delay (1000);
  digitalWrite (i,HIGH);
 }
delay (500);
}

How do you know?

for (int i=0; 1<=13; i++){
              ^^^^^   
              oops

Nice one !

Nice 1, Indeed!

Thank you sooo much.

Crazy behavior, you all should try it! makes crazy outputs after the first run, and about a minute of so later acts fine again. So interesting (troubling up till now), there must be a good use for this?

Thank you!

Well what happens is that your condition to continue the loop 1 <= 13 is always true so your variable i keeps incrementing super fast past 13 and issues the digitalWrite which do nothing on pins that do not exist. This for loop never ends and your loop never loops

Int are signed numbers coded on 2 bytes on your UNO, so after a while your int reaches 32,767 And then overflows and becomes negative at -32,768, then keeps growing and hit again 0 after a while.

So your i does

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... 32767 -32768 -32767 .... -1 0 1 2 ...

Given the delay it takes a while to do the full circle (note that 14 15 etc are valid and refer to the analog pins so you mess around with those too)