# coding error

**URL:** <https://forum.arduino.cc/t/coding-error/524406>\
**Category:** Programming\
**Created:** [May 5, 2018, 4:34pm UTC](https://forum.arduino.cc/t/coding-error/524406 "2018-05-05T16:34:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mannan12](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@mannan12](https://forum.arduino.cc/u/mannan12)\
**Post date:** [May 5, 2018, 4:34pm UTC](https://forum.arduino.cc/t/coding-error/524406/1 "2018-05-05T16:34:55Z")

</div>

here's my code :

```cpp
int LEDS = 5;
int buttonA = 9;
int buttonB = 8;
byte leds = 0;
void setup()
{
pinMode(LEDS, OUTPUT);
pinMode(buttonA, INPUT_PULLUP);
pinMode(buttonB, INPUT_PULLUP);
Serial.begin(6900);              
}
void loop()
{
if (digitalRead(buttonA) == LOW)
{
digitalWrite(LEDS,HIGH);
}
if (digitalRead(buttonB) == LOW)
{
digitalWrite(LEDS, LOW);
}
else 
digitalWrite(LEDS, HIGH);
delay(500);
digitalWrite(LEDS, LOW);
delay(500);
}
}

```

my error :

28:1: error: expected declaration before '}' token

thanks![/code]

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [May 5, 2018, 4:48pm UTC](https://forum.arduino.cc/t/coding-error/524406/2 "2018-05-05T16:48:09Z")

</div>

Do a **Tools \> Auto Format** on your code and then check the automatic indentation to make sure it matches your intended program structure.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2018, 4:51pm UTC](https://forum.arduino.cc/t/coding-error/524406/3 "2018-05-05T16:51:48Z")

</div>

(deleted)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 7, 2018, 8:02am UTC](https://forum.arduino.cc/t/coding-error/524406/4 "2018-05-07T08:02:17Z")

</div>

> pert:  
> Do a **Tools \> Auto Format** on your code and then check the automatic indentation to make sure it matches your intended program structure.

It is pointless to suggest using Tools + Auto Format, when there is clearly mis-matched curly braces. Tools + Autp Format won't work when the number of { and the number of } are not equal.

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [May 7, 2018, 11:22am UTC](https://forum.arduino.cc/t/coding-error/524406/5 "2018-05-07T11:22:26Z")

</div>

I see you say that often but I've never had that problem. Auto Format works fine for me on Windows with every IDE version I can remember using no matter how mismatched the braces are. Maybe it's an OS-specific thing? I can't imagine why that would matter

Here's mannan12's code after I did an Auto Format on it:

```cpp
int LEDS = 5;
int buttonA = 9;
int buttonB = 8;
byte leds = 0;
void setup()
{
  pinMode(LEDS, OUTPUT);
  pinMode(buttonA, INPUT_PULLUP);
  pinMode(buttonB, INPUT_PULLUP);
  Serial.begin(6900);
}
void loop()
{
  if (digitalRead(buttonA) == LOW)
  {
    digitalWrite(LEDS, HIGH);
  }
  if (digitalRead(buttonB) == LOW)
  {
    digitalWrite(LEDS, LOW);
  }
  else
    digitalWrite(LEDS, HIGH);
  delay(500);
  digitalWrite(LEDS, LOW);
  delay(500);
}
}

```

As you can see, the cause of the error is now much more obvious.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [May 7, 2018, 11:31am UTC](https://forum.arduino.cc/t/coding-error/524406/6 "2018-05-07T11:31:11Z")

</div>

> PaulS:  
> It is pointless to suggest using Tools + Auto Format, when there is clearly mis-matched curly braces. Tools + Autp Format won't work when the number of { and the number of } are not equal.

Auto Format works just as well when the number of { and the number of } are not equal. Whilst it will not (cannot) correct the error, it makes the fact that there are missing or extra brackets/braces more obvious.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 7, 2018, 12:09pm UTC](https://forum.arduino.cc/t/coding-error/524406/7 "2018-05-07T12:09:33Z")

</div>

> I see you say that often but I've never had that problem.

The IDE has been improved, then. It used to just post a red bar with "Auto Format Cancelled. Too many xxxx curly braces", where xxxx was left or right. I'll stop mentioning the issue, then.

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [May 7, 2018, 12:21pm UTC](https://forum.arduino.cc/t/coding-error/524406/8 "2018-05-07T12:21:17Z")

</div>

Actually that would a helpful message for beginners, though I wouldn't trade it for auto formatting. Maybe it was a limitation of older versions of the AStyle program the Arduino IDE uses for Auto Format.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:10pm UTC](https://forum.arduino.cc/t/coding-error/524406/9 "2021-05-05T23:10:28Z")

</div>


