and gate based on truth table I have to code in arduino the logic gates based on the truth table with two inputs. I searched for some examples, however all that I found is using &amp;&amp; to compared them using only onf if else condition. What I need is to do it using all the possible cases. This is what I have, however only the last condition is working. I ask you please clarify to me what concept I am not understanding well, or what is wrong in my logic. Thank you.

  const int p2  = 2;  //Ground G
  const int p13 = 13; //Input A
  const int p15 = 15; //Input B

  void setup() {
    // put your setup code here, to run once:
    pinMode(p2,   OUTPUT);
    pinMode(p13,  INPUT_PULLUP);
    pinMode(p15,  INPUT_PULLUP);
  }
void loop() {
  // put your main code here, to run repeatedly:
  if ( digitalRead(p13) == 0 &amp;&amp; digitalRead(p15) == 0 ){
    digitalWrite(p2, HIGH);
  }

  if( digitalRead(p13) == 0 &amp;&amp; digitalRead(p15) == 1 ) {
    digitalWrite(p2, LOW);
  }

  if( digitalRead(p13) == 1 &amp;&amp; digitalRead(p15) == 0 ) {
    digitalWrite(p2, LOW);
  }

  if( digitalRead(p13)== 1 &amp;&amp; digitalRead(p15) == 1) {
    digitalWrite(p2, LOW);
  }

}
Your whole code can be replaced with one line:

digitalWrite(output_pin, digitalRead(inputA_pin) &amp;&amp; digitalRead(inputB_pin));


That is, write out the results of a boolean AND on the state of the two inputs.