Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
Compile error · syntax

Fix “expected declaration before '}' token”

There is one closing brace too many: a } with no matching {. Auto Format (Ctrl+T) shows where the indentation breaks; delete the extra brace there.

All boardsUpdated 3 Nov 2026

Community draft — report a mistake

What you see

OutputOutput
Blink.ino:4:1: error: expected declaration before '}' token
 }
 ^
exit status 1

Compilation error: expected declaration before '}' token

Braces come in pairs. This error means the compiler found a } that closes nothing: it is outside every function, where only declarations may appear.

void setup() {
  pinMode(13, OUTPUT);
}
}          // <- extra brace: delete it

void loop() {
}

Quick fix — try in order

  1. 1

    Go to the reported line

    That } (or one just before it) has no matching {. Typically you deleted an if (…) { line but kept its closing brace.

  2. 2

    Auto Format the sketch

    Tools → Auto Format (Ctrl+T). Code after the extra brace jumps to the left margin, which shows exactly where a function was closed too early.

  3. 3

    Match every { with a }

    Click just after a brace: the IDE highlights its partner. Each function, if, for and while block needs one pair.

  4. 4

    Fix the first error, recompile

    Brace errors cause a cascade; after removing the extra one, recompile before touching anything else.

Why it happens

Why “declaration”?

After the extra } the compiler thinks it is back at the top level of the file, where only declarations are allowed. A lone } is not one.

Merged two examples

When pasting one example’s loop() body into another, it is easy to bring the closing brace of loop() along. Count braces in the pasted part.

Opposite case

A missing brace gives expected '}' at end of input instead.

Board-specific notes

Arduino IDE 2: The editor draws faint indent guides; a block whose guide stops early marks the brace that’s out of place.

↑↓ to move · Enter to open