Solved -- Why two lines cause error?

This simple code works fine

unsigned long Time1 = 0;
unsigned long Time2 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  if (millis() < 5000)
    digitalWrite(LED_BUILTIN, HIGH);
  else if (millis() < 10000)
    digitalWrite(LED_BUILTIN, LOW);
  else
    digitalWrite(LED_BUILTIN, HIGH);
}

Why does adding lines A and B cause error ‘else’ without a previous ‘if’

unsigned long Time1 = 0;
unsigned long Time2 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  if (millis() < 5000)
    Time1 = millis();               //A
  Serial.println(Time1);           //B
  digitalWrite(LED_BUILTIN, HIGH);
  else if (millis() < 10000)
    digitalWrite(LED_BUILTIN, LOW);
  else
    digitalWrite(LED_BUILTIN, HIGH);
}

if your "if/elseif/else" statements are more than one line of code you need to use curly brackets.

thats y u getting that error. C coding 101

Thank you!

sherzaad:
C coding 101

Easy for you to say! For some of us hobbyists who don't know diddly about programming these kinds of tidbits are secrets revealed :slight_smile:

sherzaad:
if your "if/elseif/else" statements are more than one line of code you need to use curly brackets.

thats y u getting that error. C coding 101

Correct, but ..

":advanced " C coding

These are NOT " curly brackets " , they are "blocks of code ".

232:
These are NOT " curly brackets " , they are "blocks of code ".

I thought they were called "braces" and they mark "statement blocks".