How to write a more compact ANDed conditions with if statement? I'm working on the rfid module and found an example that do it well. But it has a long testing the 5 bytes of the rfid received bytes, and I've tried to write it in a more compact way.

I did it with a for loop, but how to AND the conditions of the if statement?

How to change this:

if(bt0[cnt-1] == rfid.serNum[0] &amp;&amp;
   bt1[cnt-1] == rfid.serNum[1] &amp;&amp;
   bt2[cnt-1] == rfid.serNum[2] &amp;&amp;
   bt3[cnt-1] == rfid.serNum[3] &amp;&amp;
   bt4[cnt-1] == rfid.serNum[4]){
   lcd.clear();
   lcd.print("card accepted");
   digitalWrite(green_led,HIGH);
   digitalWrite(red_led,LOW);
 }
 else{
    lcd.clear();
    lcd.print("card denied");
    digitalWrite(green_led,LOW);
    digitalWrite(red_led,HIGH);
}


To something like this:

    for(byte i=0;i&lt;MXCD;i++){
      if(bt[i] == rfid.serNum[i%5]){
        cnt++;
      }
    }
    if(cnt==5){
      lcd.clear();
      lcd.print("card accepted");
      digitalWrite(green_led,HIGH);
      digitalWrite(red_led,LOW);
      cnt = 0;
    }
    else{
      lcd.clear();
      lcd.print("card denied");
      digitalWrite(green_led,LOW);
      digitalWrite(red_led,HIGH);
      cnt = 0; 
    }


In this way, I did it with 'cnt' variable to count the number of successful matched bytes then test of the number is equal to 5.

Is there a better way than this one ?

Thanks for any comments or suggestions :)
There is a standard C function for this, memcmp(). It performs a memory block compare and can be used like this: 

if (!memcmp(bt, rfid.serNum, sizeof(bt))) {
  lcd.clear();
  lcd.print("card accepted");
  digitalWrite(green_led,HIGH);
  digitalWrite(red_led,LOW);    
} 
else {
  ...
}


Ref. http://www.cplusplus.com/reference/cstring/memcmp/