and gate based on truth table
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.