Arduino错误:“在'else'之前预期不合格的id”

时间:2013-09-05 19:17:37

标签: arduino

我在第23行收到“期望不合格的id'之前'的错误,在下面的**中突出显示,在编译期间,我不确定如何解释其含义。关于它意味着什么的想法?


void loop() {                                         
  if (cycleTally <= 3) {                               
     for (count = 0, cycleTally = 0; count<3 && cycleTally==3;count++,cycleTally++) {   
          digitalWrite(led, LOW);                          //LED is dim for 250 ms
          delay (timeBlockArrayShort[count]);              //count = 1 in the array, 250 ms
          digitalWrite(led, HIGH);                         //LED is bright for 250 ms
          delay (timeBlockArrayShort[count + 1]);          //count = 2 in the array, 250 ms
}
}
**else** {                                             //error location
if (cycleTally <= 6) {                            //
  for (count = 0, cycleTally = 4; count<3 && cycleTally==6;count++,cycleTally++) {
     digitalWrite(led, LOW);
     delay (timeBlockArrayLong[count]);
     digitalWrite(led, HIGH);
     delay (timeBlockArrayLong[count + 1]);
  }
  }

1 个答案:

答案 0 :(得分:1)

您应该开发自己的风格或规则来格式化代码,以便明确括号如何配对:

void loop() 
{                                         
  if (cycleTally <= 3)
  {                               
     for (count = 0, cycleTally = 0; count < 3 && cycleTally == count++,cycleTally++)              
      {   
         digitalWrite(led, LOW);                 //LED is dim for 250 ms
         delay (timeBlockArrayShort[count]);     //count = 1 in the array, 250 ms
         digitalWrite(led, HIGH);                //LED is bright for 250 ms
         delay (timeBlockArrayShort[count + 1]); //count = 2 in the array, 250 ms
      }  // end for

  } else {                 //error location ??
      if (cycleTally <= 6)
      {
           for (count = 0, cycleTally = 4; count<3 && cycleTally==6;count++,cycleTally++)
           {
              digitalWrite(led, LOW);
              delay (timeBlockArrayLong[count]);
              digitalWrite(led, HIGH);
              delay (timeBlockArrayLong[count + 1]);
           }  // end for
       }

   } ///<<<<< THIS WAS MISSING after formatting!!!

因此,当一个}或{缺失。

时,漂亮,干净的代码会很明显