"for loop" on arduino

Hi everybody, I have a little problem about "for loop" on my main program.

char code;

void setup()
{
  Serial.begin(9600);
}

void loop()
{

  while(Serial.available() <= 21){};
  for(int i = 0; i < 22; i++)
  {
    code = Serial.read();
    Serial.print(code);
  }
  Serial.print(code); 
  delay(2000);
  Serial.flush();
}

I cant read the variable "code" outside of the "for loop", i can only read her value on the loop

I cant read the variable "code" outside of the "for loop", i can only read her value on the loop

You change the value stored in the one variable 21 times. Only the last value will be available outside of the for loop.

Oh, ok
So how can i store these values on array and then read it outside the "for loop"

So how can i store these values on array

You store them IN an array. They fall off if you try to store them ON an array.

  char myArray[30];
  for(int i = 0; i < 22; i++)
  {
    myArray[i] = Serial.read();
    Serial.print(myArray[i]);
  }
  myArray[22] = '\0';

and then read it outside the "for loop"

  Serial.print("myArray contains: [");
  Serial.print(myArray);
  Serial.println("]");

Ok thank you but the result of ur code its : myArray contains: [FF2E9E010B01010D125B08YóS]

thats good but there are "YóS" at the end and i wont it on my array !

my code :

char code[22];
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  while(Serial.available() <= 22){}
  for(int i = 0; i < 22; i++)
  {
    code[i] = Serial.read();
  }
  Serial.print(" myArray contains: [");
  Serial.print(code);
  Serial.println("]");
  Serial.flush();
}

Oh ok nothing thats right i read the good code of my badge
So now i want to compare the value of the array betwen a string like "FFFSSDSQDq444" so how can i do it ?

These are pretty basic questions. You need to start researching this stuff yourself. Googling "compare C strings" got me 44.8 million hits. I'll bet one of those will likely help you answer your own question.