Reading last sent command from Serial

So I last worked on making a while loop work, and now here's this problem-
In my while loop, I have it so if it does not read a command that says 4, it makes the LED blink, and if the command "4" has been given, it is supposed to make the while loop break.

So far, I have it in an if-else structure, so is there a way to make the Arduino read the last command sent (as in save the command that was sent via the serial and read it later)? Because Serial.read does not seem to work.

Here's the code, in case I am doing something else wrong-

void blinkmode(){
  int blinkmodeon = 1;
  while (blinkmodeon == 1)
  {
    if (Serial.available() > 0){
      int command = Serial.read();
      if (command == '4') {
        blinkmodeon == 0;
      }
    }
    else {
      digitalWrite(ledPin, HIGH);
      delay(500);
      digitalWrite(ledPin, LOW);
      delay(500);
    }
  }    
}

This doesn't seem to do what you think it will..

Move blinkmodeon outisde the function. It will always be set to 1 when you enter the function (probably right after you set it to 0 and the while loop ends). No way to know without the rest of the coude though...

This:

       blinkmodeon == 0;

Should be this:

       blinkmodeon = 0;

wildbill: nice catch :slight_smile:

Toxic: If you don't need to keep the state a simple return or break would suffice instead of keeping a variable around

wildbill:
This:

       blinkmodeon == 0;

Should be this:

       blinkmodeon = 0;

AAAAAAAAAAAAAAAAAAAAAARGH
I keep forgetting those sorta things Dx

remiss:
wildbill: nice catch :slight_smile:

Toxic: If you don't need to keep the state a simple return or break would suffice instead of keeping a variable around

Yeah, I need to start doing that more. :.