can't upload new programs after uploading a specific sketch

int r1=1,r2=2,r3=3,r4=4,r5=5;
int c1=9,c2=10,c3=11,c4=12,c5=13;
void setup() {
  // put your setup code here, to run once:
for (int i=1;i++;i<=5)
  {
    pinMode(i,OUTPUT);
    digitalWrite(i,0);
  }
for (int i=9;i++;i<=13)
  {
    pinMode(i,OUTPUT);
    digitalWrite(i,0);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(r1,1);
digitalWrite(c3,1);
delay(10);
digitalWrite(r1,0);//
digitalWrite(c3,0);//
digitalWrite(r2,1);
digitalWrite(c2,1);digitalWrite(c4,1);
delay(10);
digitalWrite(r2,0);//
digitalWrite(c2,0);digitalWrite(c4,0);//
digitalWrite(r3,1);
digitalWrite(c1,1);digitalWrite(c5,1);
delay(10);
digitalWrite(r3,0);//
digitalWrite(c1,0);digitalWrite(c5,0);//
digitalWrite(r4,1);
digitalWrite(c2,1);digitalWrite(c4,1);
delay(10);
digitalWrite(r5,1);
digitalWrite(c3,1);
delay(10);
digitalWrite(r5,0);//
digitalWrite(c3,0);//
}

this code was written to test the muxing of 5x5 led matrix.
After i upload the above program in my Arduino duemilanove, i'm always facing the same problem again and again. I can't upload any other sketch afterwards. When i try to upload them, it show the following error:-

stk500_getsync() attempt 3 of 10: not in sync: resp=0xea

i can only get out of the problem only when i keep the reset button pressed during connecting my cable to PC and releasing the button exactly before the upload process starts.

i have tried this more than 3 times. the same problem occurs every time. you can try this too. but beware : the only way to get out of the problem is to releasing reset button exactly before upload starts.

I have tried uploading other codes after getting out of the problem. But none of them caused the problem.
Can anyone explain me why this particular code is causing the above problem every time?

That's very interesting - There are few ways indeed to hose the upload from within a sketch on something that doesn't have native USB (like a Leo/Micro/Due - those it's pretty easy on). The duemillanove has the dtr autoreset, which asserts the hardware reset pin - come hell or highwater, there's nothing your sketch can do to prevent the hardware reset pin from generating a reset condition.

I suspect it's related to your use of pin 1, which is one of the pins used for serial upload, specifically TX. Suppose the change in state as the board is reset is mistaken for serial data transmission... it would then look at that first character (actually garbage) and declare that an unexpected character and abort the upload.

The for loop expression order is wrong; the condition expressions and iteration expressions are reversed. I suspect that will overflow the int and foul up the serial pins.

Edit: It is most likely that if you have an LED on a serial pin then the full swing of logic levels won't be seen at the pin.

you guys are really genius.salute. :grin: :grin: :grin: