Can somone help me see what is wrong here, and understand it

This looks simple, and I have books to reference what I am doing, but I can’t see what it generates simple errors that I can’t fix, so I think that the error is not referencing what is really wrong. Can someone explain what is wrong and why?

void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
int c = 1;
)
while (c < 400) {
digitalWrite(9, HIGH);
delay(1);
digitalWrite(9, LOW);
delay(1);
c++;
}

  )

Pay attention to the difference between a ) and a }. They are not the same.

The code formatted better

void setup()
{
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  int c = 1;
  )
  while (c < 400)
{
  digitalWrite(9, HIGH);
    delay(1);
    digitalWrite(9, LOW);
    delay(1);
    c++;
  }

Where should the setup() function end ?
Where does the loop() function end ?
What is the scope of the c variable declared in setup() ?
Which commands should be conditionally executed in the while loop ?
Why is the while command outside of a function ?

UKHeliBob:
Why is the while command outside of a function ?

It isn't

AWOL:
It isn't

Which function is it in ?

Well, assuming the orphan ) is a typo, it's in an incomplete setup.

Well, assuming that the orphan ) was meant to be a } it is not in a function :slight_smile:

Ok, so I got a lot of questions instead of answers. I am 61, and retired, and this all looked simple, yet would not compile, and I didn't understand the error messages. So if someone corrected the code and let me see it with a small explanation about what I did wrong, I would learn from that. The questions can't teach me anything without a whole lot of reading to figure out what the questions mean.

Anyone who is feeling irritated by my learning experience, please try not to post that irritation in the form of something that was meant to help, and teach me what I did wrong.

I did fix the one obvious mistake, but there is something else wrong, and the compiler doesn't do anything to help me at my low level.

The code you posted is not a complete Arduino program, in addition to containing syntax errors.

The following is a complete program and it compiles.

Whether it does what you want is not clear, because you have not told us what that might be.

Please read the “How to use this forum” post for hints on how to get useful advice.

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  int c = 1;
  while (c < 400) {
    digitalWrite(9, HIGH);
    delay(1);
    digitalWrite(9, LOW);
    delay(1);
    c++;
  }
}
void loop() {}

I did fix the one obvious mistake,

There were several potential mistakes, even when the "obvious" was fixed (whatever "fixed" means), which made it hard to judge the intent of the code.

yet would not compile, and I didn't understand the error messages.

So it would have helped tremendously if you would have posted the error message that you didn’t understand then we could have explained what it meant.

You should always post all your code and say what it does and more importantly what you expected it to do.

We have to aske questions of you if you fail to supply enough information for us to get a picture of what you are doing and what you want to do.

LearningIsFun:
Can someone explain what is wrong and why?

Yes:

void setup() {
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 digitalWrite(8, LOW);
 digitalWrite(9, LOW);
 int c = 1;
 )    <<<<<<<<<<<<  You can't have a ')' sitting there by itself.
 while (c < 400) {
 digitalWrite(9, HIGH);
   delay(1);
   digitalWrite(9, LOW);
   delay(1);
   c++;
 }
<<<<<<<<<<<<<<  You didn't put in a '}' to end the setup() function.


<<<<<<<<<<<<<< You didn't declare the required 'loop' function:  void loop() {}

The first error message is:

/Users/john/Documents/Arduino/sketch_jul16a/sketch_jul16a.ino: In function 'void setup()':
sketch_jul16a:8: error: expected primary-expression before ')' token

   )

   ^

That is pointing out that the ‘)’ on line 8 makes no sense without something in front of it. If you add random stuff in front of it you will find that it still doesn’t make sense.

After that ‘)’ is removed, the first error is:

/Users/john/Documents/Arduino/sketch_jul16a/sketch_jul16a.ino: In function 'void setup()':

sketch_jul16a:16: error: expected '}' at end of input
   }
   ^

This is telling you that you left out a ‘}’ (or accidentally put in an extra ‘{’).
After that ‘}’ is added, the first error message is:

arduino.ar(core_esp8266_main.cpp.o):(.text._ZL12loop_wrapperv+0x4): undefined reference to `loop'
arduino.ar(core_esp8266_main.cpp.o): In function `loop_wrapper':

That is telling you that you forgot to declare the required ‘loop()’ function.