Expected primary-expression before 'if' *HELP PLEASE*

I'm programming a project to have a line of leds blink back and forth and for a person to press a button and try to get the led to stop on the middle (target) led. My program gets an error that says "Expected primary-expression before 'if'" could anyone help as soon as possible? thanks!

_7_LED_Loop.ino (1.46 KB)

  for int thisPin = 8;

Huh?

 // use a for loop to initialize each pin as an output:
  for (int thisPin = 5; thisPin < 12; thisPin++)  {
    pinMode(thisPin, OUTPUT); 
    int buttonState = 0;        // variable for reading the pushbutton status
const int buttonPin = 2;     // the number of the pushbutton pin
  }

buttonState and buttonPin are local variables (inside the braces). Since you aren't using them there isn't much point in having them.

    if buttonState == HIGH

Better read up on the syntax of the C++ language. Or look at some examples. Or both.

Hi, welcome to the forum.

Your indents (the text layout) is not consistent. So it is hard to see that you have code outside the loop() function. There Arduino has a auto-format function, it is in the menu.

This should not be in setup(), but above it: const int buttonPin = 2;
This is wrong: for int thisPin = 8;
And also the next line.

(Nick Gammon wrote about the same, while I was writing this)