String comparison not working

I am trying to compare a string to a series of letters. My code uploads and it will store the a and b I type in, but will not print equal when I type in three a. I am new to using strings so it could be an obvious problem. Any help would be very appreciated.

String charStorage;
int inByte = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
if (Serial.available() > 0) {
int inByte = Serial.read();
switch(inByte){
case 'a' :
charStorage += 'a';
Serial.println(charStorage);
break;
case 'b' :
charStorage += 'b';
Serial.println(charStorage);
break;
if(charStorage == "aaa" ){
Serial.println("equal");
}
}
}
}

Use Tools|Auto Format in the IDE to straighten out your code. You will then perhaps see that the if statement isn't in the right place.

Pete

Take the if statement out of the switch statement.

Thank you. That fixed it. This is helpful.

You really should be using strcmp() to compare strings, not ==.

You really should be using strcmp() to compare strings, not ==.

But s/he is using Strings, not strings, so == is fine.

(Does the String class even have a "strcmp" method?)

Does the String class even have a "strcmp" method?

No, but OP should learn how to NOT use the String class. It's a damned resource hog, and provides little value in such a trivial program.

I can't disagree, but if the question relates to the String class, I feel we should respond in like.