If statement

Hi, I am at the very beginning with Arduino. Can some tell me what I am doing wrong with this basic sketch?

I getting a message saying that "I using an ELSE without an IF.

void setup() { // put your setup code here, to run once: Serial.begin(9600); }

void loop() { // put your main code here, to run repeatedly: char x = "A"; if (x = "y"); { Serial.print("Yes"); } else { Serial.print("NO"); } delay(2000); }

“Can some tell me what I am doing wrong ” You are posting your question in the wrong forum.

Did you read the top thread in this forum?

Here is some example code from the Arduino Reference page on If Else statements:

if (condition1) {
  // do Thing A
}
else if (condition2) {
  // do Thing B
}
else {
  // do Thing C
}

Here's your code:

if (x = "y"); {
  Serial.print("Yes");
}
else { Serial.print("NO");
  }
  delay(2000);
}

Do you notice anything different? Specifically with the amount of semicolons?

You might also want to remember that = assigns values, x = 2 means make x equal to 2. If you want to compare things you use ==.

One of the tricky things to get at first about C++ is that both spelling and punctuation are vitally important. The compiler doesn't even try to guess what you might have meant.

Steve