Problem with domain maximum/minimum for loop

How do I create a minimum and maxium limit in a for loop? Ive only been able to make a maximum or minimum. Like x < 8. Ive already tried 0 < x < 8 and (x<8)||(x>0)

int LED[] = {10, 2, 3, 4, 5, 6, 7, 8};
int pinCount = 8;
int taster = 11;
int x = 0;
int f = 1;

void setup() {
 Serial.begin(9600);
 for(int pinZahl = 0; pinZahl < pinCount; pinZahl++) {
	pinMode(LED[pinZahl], OUTPUT);
	}
	pinMode(taster, INPUT_PULLUP); 
}

void loop()
{
  if(x == (pinCount)){
    x = 7;
    f = -1;
    }
  if(x == 1){
    x = 0;
  	f = 1;
  }

  for(x;(x<(pinCount))||(x>0); x+=f){
       digitalWrite(LED[x], 1);
       delay(500);
       digitalWrite(LED[x], 0);
    	Serial.print(x);
       }
}

(x<8)||(x>0)
is equivalent to
(x<8) OR (x>0).

If you need
(x<8) AND (x>0)
try to
(x<8) && (x>0)

If I use (x<8)||(x>0) he goes beyond 8 and counts 9,10,11,12,13,14 but I dont know why.

Because
x<8)||(x>0)
is equivalent to
(x<8) OR (x>0).

So the expression will be true if ANY of the two conditions is true.
If x = 9(and 10,11,12...), the condition x>0 is true, so the entire expression will be true too.

For troubleshooting the OP might want to enable serial prints and add in some serial prints so see what the thing is.

void loop()
{
  if(x == (pinCount)){
    x = 7;
    f = -1;
    }
  if(x == 1){
    x = 0;
  	f = 1;
  }

Serial.print( "x= ");
Serial.print ( x );
Serial.print( " pincount = " );
Serial.print.( pincount);
Serial.print( " f =");
Serial.print (f);
Serial.println();
  for(x; x<(pinCount));  x+=f){
       digitalWrite(LED[x], 1);
       delay(500);
       digitalWrite(LED[x], 0);
    	Serial.print(x);
       }
}

Ah I realised what you meant. :sweat_smile:

Are you trying to make a LED run up and down?

void loop()
{
  x += f;
  if (x >= pinCount) {
    f = -1;
  }
  else if (x <= 0) {
    f = 1;
  }
  digitalWrite(LED[x], 1);
  delay(500);
  digitalWrite(LED[x], 0);
  Serial.print(x);
}

or even

void loop()
{
  x += f;
  if (x >= pinCount or x <= 0) {
    f = -f;
  }
  digitalWrite(LED[x], 1);
  delay(500);
  digitalWrite(LED[x], 0);
  Serial.print(x);
}

Yeah 8 LEDs running up and down but I have to use the for loop, which makes it more complicated than it actually is. :joy:

Then

int LED[] = {10, 2, 3, 4, 5, 6, 7, 8};
int pinCount = 8;
int taster = 11;
int x = 0;
int f = 0;

void setup() {
  Serial.begin(9600);
  for (int pinZahl = 0; pinZahl < pinCount; pinZahl++) {
    pinMode(LED[pinZahl], OUTPUT);
  }
  pinMode(taster, INPUT_PULLUP);
}

void loop()
{
  for (x = 0; x < pinCount; x++) {
    digitalWrite(LED[x ^ f], 1);
    delay(500);
    digitalWrite(LED[x ^ f], 0);
    Serial.print(x);
  }
  f = ~f & 7;
}

Topic closed as duplicate of:

@loetmeister cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.