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);
}
}
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.
@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.