For loop with if statement for ardiuno powered humidity control

Really simple question but I’m not entirely sure how to incorporate a for loop in the if statement I have. Context: I have a humidifier I am trying to automate based on the humidity of the room. I’m using an ardiuno, dht11 humidity sensor and a servo. The humidifier knob has three settings (high low off) and so the servo has three positions. I have the code running so the servo turns appropriately according to the humidity level. The issue is that it fluctuates very easily. To correct that I’m looking to incorporate a for loop so that after let say 60 one second iterations of the humidity being greater than 55 the servo moves. I tried to add a for loop but it doesn’t seem to be working.

But this is only my solution based on the little programming I know. If there is a better solution or even an equally viable alternative I’d love to know. I’m currently studying mechanical engineering but I’m finding that to really make something one needs a background in electronics and code. I’m trying to learn both independently through a series of projects and so I’m quite eager to learn. Hopefully this helps explain why I’m asking such a simple questions to begin with.

#include <dht.h>
#include <Servo.h>
Servo myservo;//create servo object to control a servo

dht DHT;

#define DHT11_PIN 7 // pin for humidity sensor ( also measure temp)

void setup() {
myservo.attach(9);//attachs the servo on pin 9 to servo object
myservo.write(0);//statting off position at 0 degrees
delay(1000);//wait for a second


void loop() {
int chk = DHT.read11(DHT11_PIN); // the follow is just so that I can see the readings come out properly
Serial.print("Temperature = ");
Serial.print("Humidity = ");

if (DHT.humidity > 55) // here is where my code really begins
for (int i=0; i>60; i++); // my goal is to execute the follow code after the statement above has been true for 60 one second iterations
myservo.write(0);//goes to off position
delay(1000);//wait for a second
} else if (DHT.humidity > 40 ) {
for (int i=0; i>60; i++); // same thing here
myservo.write(90);//goes to low position
delay(1000);//wait for a second

for (int i=0; i>60; i++);
myservo.write(180);//goes to high position
} // end of void loop()

I had a similar problem when I replaced a timer based defrost with a demand based defrost in my heat pump.
Part of the code reading temperature sensors are from example code so variable names is a bit off, but I think you get the idea.
I read temperature every 5 seconds, and it is needed 12 readings with defrost needed before it will start. A single reading without need will reset counter back to zero.

void loop(void)
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  delay (3000);
  tempOutside = sensors.getTempC(insideThermometer);
  tempBoiler = sensors.getTempC(outsideThermometer);
  deltaT = tempOutside - tempBoiler;
  Serial.println (tempOutside, 3);
  Serial.println (tempBoiler, 3);
  Serial.println (deltaT, 3);
  if ((deltaT > 6) && (tempBoiler < -3.5) && (defrostActive == 0)) {
    Serial.println ("Counting up");
  else if (defrostNeeded > 0) {
    defrostNeeded = 0 ; //Reset counter if there is no need
  delay (2000);

  Serial.println (defrostNeeded);
  Serial.println (tempOutside, 3);
  Serial.println (tempBoiler, 3);

  if (defrostNeeded > 12 && defrostActive == 0) { //60 sec demand before actual start
    defrostActive = 1;
    defrostNeeded = 0;
    Serial.println ("Begin defrost");
    digitalWrite (RELAY1, HIGH);
    timeStart = millis();

  timeRun = millis() - timeStart;

  if (defrostActive == 1) {
    if (timeRun > 720000 || tempBoiler > 10) { //12 min max time or 10 degrees in boiler.
      digitalWrite (RELAY1, LOW);
      defrostActive = 0;
      delay(1800000); //30 min delay before next cycle allowed. 


     for (int i=0; i>60; i++);

The body of your for loop is the ; on the end. That is a no-op. Doing nothing 60 times won't accomplish a thing.

What you are really looking for is called hysteresis. You move the servo only if the humidity has changed a significant amount, not any amount.

Now PaulS has mentioned the for loop, I see i>60. Condition will evaluate to false at first iteration.