‘else’ without a previous ‘if’ C++ [closed]

  arduino-uno, c++

I was trying a if, Else If statement in a While loop in C++ for my Arduino project, but it was showing me an error, My arduino project was basically starting a timer from 9 in a seven segment LED –

Please help me with this error, My code is here

while(i < 10){
    if(i == 9){
      for(int a = 0; a < 7; a++){
        digitalWrite(nine[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 8){
      for(int a = 0; a < 8; a++){
        digitalWrite(eight[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 7){
      for(int a = 0; a < 4; a++){
        digitalWrite(seven[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 6){
      for(int a = 0; a < 7; a++){
        digitalWrite(six[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 5){
      for(int a = 0; a < 6; a++){
        digitalWrite(five[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 4){
      for(int a = 0; a < 5; a++){
        digitalWrite(four[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 3){
      for(int a = 0; a < 6; a++){
        digitalWrite(three[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 2){
      for(int a = 0; a < 6; a++){
        digitalWrite(two[a], HIGH);
      }
    }
    delay(1000);
    else if(i == 1){
      for(int a = 0; a < 3; a++){
        digitalWrite(one[a], HIGH);
      }
    }
    delay(1000);
    else{
      for(int a = 0; a < 7; a++){
        digitalWrite(zero[a], HIGH);
      }
    }
  }```

Source: Windows Questions C++

LEAVE A COMMENT