millis() vs delay()

Hi I have read through the guide thread which explains difference between the two and I understand delay()holds everything up so millis() needs to be used when there are several things happnening at the same time. But the codes below doesn't require several things at the same time. i.e when push button is pushed, fan gets switched on. Why is mills() being used instead of delay(50)?
int buttonPin=2;
int relayPin=3;
int relayState=HIGH;
int buttonState;
int lastButtonState=LOW;
long lastDebounceTime=0;
long debounceDelay = 50;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, relayState);
}

void loop() {
// put your main code here, to run repeatedly:
int reading=digitalRead(buttonPin);
if(reading!=lastButtonState){
lastDebounceTime=millis();
}
if((millis()-lastDebounceTime)>debounceDelay){
if(reading!=buttonState){
buttonState=reading;
if(buttonState==HIGH){
relayState=!relayState;
}
}
}
digitalWrite(relayPin,relayState);
lastButtonState=reading;
}

But the codes below doesn't require several things at the same time.

The code reads an input pin and it writes an output pin. Two things that you want done at the same time.

PaulS:
The code reads an input pin and it writes an output pin. Two things that you want done at the same time.

thanks what are the two things they try to do at once?

It's easier to read when correctly indented:

void loop() {
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
        relayState = !relayState;
      }
    }
  }
  digitalWrite(relayPin, relayState);
  lastButtonState = reading;
}

The whole thing is about debouncing. These lines read the button and compare it with the current state:

  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {

If the state changed, the code initiates a chrono and waits until debounceDelay

  if ((millis() - lastDebounceTime) > debounceDelay) {

to take into account this change (to change the relay state)

During that waiting interval

  lastButtonState = reading;

it stops comparing the state button.

Not very easy...

ppok1989:
thanks what are the two things they try to do at once?

Are your reading comprehension skills that lacking? I told you what the two thing were in the first paragraph.

PaulS:
The code reads an input pin and it writes an output pin. Two things that you want done at the same time.

The reading of the input pin gets done if it has changed the output pin get switched to a different state and then reading of the input pin continues.