Is digital I\O #4 different than #2?

Hello,

I have an Arduino Nano board that I am working with. I am having some trouble with some very simple code (see below) that works precisely as expected when the input is #2 but works differently when the input is #4. When the input is #2 pressing the button (attached to i/o #2) results in printing "on"...releasing results in printing "off". However when the input is #4 pressing the button (now attached to i/o #4) results in "on" then "off" being printed...releasing the button has the same result...prints "on" then "off".

Here is the code

const int Switch     = 4;        // pin connected to the push button

int State              = 0;        // state of the button
int lastState          = 0;        // previous state of the button

void setup() 
{
    // initialize the button pin as a input:
    pinMode(Switch, INPUT);
    
    // initialize serial communication:
    Serial.begin(9600);
}

void loop() 
{  
    //int vidState = DebounceInput(videoSwitch, lastVidRead, lastVidDebounce);
    State = digitalRead(Switch);
    
    
    // if the state of the On\Off button has changed
    if (State != lastState)
    {    
        // if the on/off button was pressed...
        if (State == HIGH)
        { 
            Serial.println("On");
        }
        else
        { 
            Serial.println("Off");
        }
    }
    
    lastState = State;
}

Is there something special about pin 4? Does it somehow function differently? Do I need to do something different to set it up?

Thanks in advance for any help with this. Steve

Did you try turning on the internal pullup so you get a consistent high reading unless the pin is pulled low?

Have you looked at the schematic of the nano to see there is other hardware connected, like an external pullup or pulldown resistor?

Are you using the same switch in both cases?