Pause in the program for some time I have a variable timeInSec which records the time as loop begins. It is defined as timeInSec = millis();. I have two conditions. If (timeInSec - lastRun)&lt; 5 (that is 5 sec) , the first condition is executed(the if statement).Otherwise if (timeInSec - lastRun)&gt;5 the second condition is executed(else statement). Here is the code:

void loop(){
  timeInSec = millis();  // Records time in seconds
  // if(lastRun &gt; 0) {   // if i run this, only else statement is executed
  // delay(10000);
  // }
  if((timeInSec - lastRun) &lt; 5000){  // Treshold time (if condition which runs when timeInSec is less than 5 seconds)
    // Some code
  }
  else{ // If treshold time exceeds (executes when timeInSec is &gt; 5seconds)
   delay(10000);  // if i run this, only else statement is executed
   lastRun = timeInSec;
  }
}


Here the else statement executes once and control goes back if statement again. I want to pause the control at else statement for 10 seconds and then go back to if statement for further execution. Everytime  the control should pause at else statement for 10 seconds. I have used delay in the else statement and in this case only else statement is being executed. The same happens if I use delay at the start of loop (as in code). I have tried without using delay but didn't succeed. 

Thanks for the help!
Do not try to change millis(). Instead, record the last time the
second code (else statement) ran, and check whether that was more than
five seconds ago:

void loop() {
    static uint32_t lastRun;
    uint32_t now = millis();
    if (now - lastRun &lt; 5000) {
        // Some code
    }
    else {
        // Some code
        lastRun = now;  // record the time
    }
}


This is essentially the same technique used in the Blink without
delay Arduino
tutorial.