0

在编译过程中,我在第 23 行收到“在 'else' 之前预期的不合格 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]);
  }
  }
4

1 回答 1

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!!!

因此,当 } 或 { 丢失时,漂亮、干净的代码会很明显。

于 2013-09-06T00:23:53.297 回答