button switches are typically connected between a pin a ground and requires the pin be configured as INPUT_PULLUP which enables an internal pullup resistor making the pin HIGH when the pin is no pressed and LOW when pressed.
the code performs an action (i.e. x++) when the input is HIGH, which as I said above, is the state when the button is not pressed.
but don't you also want the code to only x++ once when the button is pressed. so the code needs to track the button state and check for a state change and only x++ when there's a state change and the input if LOW