Trying to print "occur = 1" in an if statement but it wont work Cant seem to get this code to work with my arduino, and yes its all hooked up properally, even used leds to show that the button is being pressed, what am i doing wrong or dont know?

const int digitalInPin3 = 8;     //switch
int Occur = 0;
int Switch = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
int Switch = digitalRead(digitalInPin3);

if (Switch == 1){
  int Occur = 1;
}


else {
 int occur = 2;
}

   Serial.print("\t Switch =");
   Serial.print(Switch);
   Serial.print("\t occur =");
   Serial.println(Occur);

  delay(1);
}
Remove the int from inside the if and else statement. The code would always show 0 because access of occur, which is assigned value 1 or 2 is limited to the if..else statement. So the global occur remains 0 always.

So change it to:

if (Switch == 1){
 Occur = 1;
}
else {
 Occur = 2;
}


This will work.