Cannot figure why my code ignores the second for())

int T = 50; int T = 50;
int p[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //
void setup(){ void setup(){
Serial.begin(9600); Serial.begin(9600);
for(int i=0; i<14; i++){ for(int i=0; i<14; i++){
pinMode(p[i],OUTPUT); pinMode(i, OUTPUT);
Serial.print(set: ); Serial.print(set: );
Serial.println(p[i]); Serial.println(i);
delay(T); delay(T);
} }
} }
void loop(){ void loop(){
Serial.print(marker ); Serial.print(marker );
for(int i=0; i<14; i++){ for(int i=0; i<14; i++){
digitalWrite(p[i], HIGH); digitalWrite(i, HIGH);
Serial.print(up: ); Serial.print(up: );
Serial.println(p[i]); Serial.println(i);
delay(T); delay(T);
} }
for(int i=13; i>=0; i--){ for(int i=13; i<=0; i--){
digitalWrite(p[i], HIGH); digitalWrite(i, HIGH);
digitalWrite(p[i], LOW); digitalWrite(i, LOW);
Serial.print(down: ); Serial.print(down: );
Serial.println(p[i]); Serial.println(i);
delay(T); delay(T);
} }
} }

can someone please help me out for I haven’t programmed in a long time. The program on the left is correct, it’s an example from the help files. The program , I wrote, on the right does not want to do what I wanted it to do and that is go to the next for(). When i=13 it always goes to beginning loop() and ignores the second for(). as you can see it is identical to the example on the left excluding the array setup. I’ve spent many hours trying to figure this out. Could anybody help me and explain why my program does not go to that second for()??

Post both pieces of code properly... in code tags. You'll get a lot more help.

1 Like
for(int i=13; i<=0; i--){

Because 13 is not less or equal to zero, the loop is skipped.

i<=0 is never true.. loop stops.

Not really...

image

No, the code on the left says

for(int i=13; i>=0; i--){

13 is greater or equal to zero, so the loop runs.

Although it's nice to be able to compare line for line, it's far more difficult to read if you don't use code tags. Most of the more experienced users also have the tools to do the compares. So please post the two codes individually using code tags (the 'circled' in below).

https://europe1.discourse-cdn.com/arduino/original/4X/7/6/0/76068b67427cb74e7360e74c52e2dd4455071975.png

1 Like

well, I feel like an idiot. thank you for all your responses.

Don't... everyone made and still makes errors like that; we're human.

Hi
There are people who are not.... :grinning: :grinning: :grinning: :grinning:
243-Adesivo-Eu-nao-sou-um-robo-Nerd-Stickers

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.