Switch Being unreliable

Hi all I have the following code, I only included the relevant parts

int inPin=23;
int outPin=22;

void setup(){
Serial.begin(38400);
  pinMode(inPin,INPUT);
  pinMode(outPin,OUTPUT);
  digitalWrite(outPin,HIGH);
}

void loop(){
  if(digitalRead(inPin)==HIGH){
    Serial.println("HIGH");
   }
   else{
     Serial.println("LOW");
    }
    delay(100);
}

This is producing shakey outputs(when not touching anything) like as follows HIGH HIGH HIGH HIGH LOW LOW LOW LOW LOW LOW LOW LOW HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH HIGH

I have tried different switch's and get the same problem. If anyone knows the solution that would be greatly appreciated.

If you've wired the switch to pull the pin to ground but have no external pullup, use INPUT_PULLUP instead of INPUT for the pinMode.

Without a pullup (internal or external) the pin is floating when the switch is open; this is never a good thing for high-impedance digital (or analog) inputs.

Thank you, that helped