Arduino has problems comparing two numbers???

Hi,
Today I am experiencing a very strange problem...
Im working on a project in which if i push and release a button, a variable increases by one.
And when it reaches 5 it should be back at 0.
It seemed to me that nothing happens so I added some Serial.print()-s to see what the problem is.

The code is:

  //Read OK button
  int reading = !digitalRead(buttonPins[3]); //Invert the reading cuz we are using internal pullup resistor
  Serial.println(reading);
  if(reading != lastButtonStates[3])
  {
    lastDebounceTimes[3] = millis();
  }

  if(millis() > (lastDebounceTimes[3] + debounceTime) )
  {
    if(buttonStates[3] != reading)
    {
      buttonStates[3] = reading;
      if(buttonStates[3] == LOW)
      {
        setting++;
        Serial.print("S");
        Serial.println(setting);
        if(setting > 5);
        {
          
          Serial.print("X");
          Serial.println(setting);
          setting = 0;
          
        }
      }
    }   
  }

  lastButtonStates[3] = reading;

And what happens is: When i release the button it writes S1 and X1 at all times.
So it means that when i release the button it increases the value bye one, but for some reason Arduino thinks that 1 is greater than 5 and it runs the lines which should run only when x > 5. I tried that i change the condition to x==6 but the same result.

I have a warning: Low memory available, stability problems may occur.
Might this be in connection with that?
I am using the Adafruit ssd1306 library with the Adafruit GFX library to use an OLED display.

Thanks in advance for any help.

dagoston93

Here’s your problem:

dagoston93:

        if(setting > 5);

The semicolon at the end means that if setting is greater than 5 do nothing, then run the code in the following braces always. Remove the semicolon and the code should work as expected.