Hi @meriam_12 ,
it's not so hard once you start to "think like a computer" 
Let's look at the loop() only and remove the second "if" to make it easier ...
void loop() {
// This is line #1. It stores the actual time in milliseconds
newTime = millis();
// Now we calculate the interval between "newTime" and "oldTime"
// This is the time in milliseconds expired since the last time we have stored oldTime
timeDelay = (newTime - oldTime);
// As long as this difference is less than or equal to 1000 msecs
// everything inside the if-clause is skipped!
if (timeDelay > 1000 && ledOn == 0) {
digitalWrite(led, HIGH);
ledOn = 1;
oldTime = newTime;
timeDelay = 0;
}
// This is the line after this if-clause
// and the end of loop()
// so the controller will proceed with line #1 again
}
You can see that everything inside the if-clause is skipped until the interval has expired.
When the time has expired the if-clause will be entered and ledOn is set to 1 and oldTime to the recent time inside it.
From now on the controller will never again enter the if-clause as long as ledOn stays 1 ...
Now the second if-clause has a chance to be entered:
if (timeDelay > 1000 && ledOn == 1) {
digitalWrite(led, LOW);
ledOn = 0;
oldTime = newTime;
timeDelay = 0; // This is a corrected line, however
// not necessary here as timeDelay is calculated
// in loop() before it is evaluated by the first if-clause
}
It has to wait again until timeDelay has expired and then the content will be performed:
(Actually it does not "wait" ... The content of the if-clause is just skipped until the conditions of the "if" are met).
Inside the second if clause ledOn is set to 0 again and oldTime to the recent time.
Now verything starts from the beginning...
You can change the loop() as follows:
const int led = 13;
unsigned long oldTime;
unsigned long newTime;
unsigned long timeDelay;
boolean ledOn;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
newTime = millis();
timeDelay = (newTime - oldTime);
if (timeDelay > 1000 ) {
if (ledOn == 0) {
digitalWrite(led, HIGH);
ledOn = 1;
} else {
digitalWrite(led, LOW);
ledOn = 0;
}
oldTime = newTime;
}
}
or even shorter
const int led = 13;
unsigned long oldTime;
unsigned long newTime;
unsigned long timeDelay;
boolean ledOn;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
newTime = millis();
timeDelay = (newTime - oldTime);
if (timeDelay > 1000 ) {
ledOn = 1 - ledOn; // if ledOn is 0 the result is 1, if ledOn is 1 the result is 0
digitalWrite(led, ledOn);
oldTime = newTime;
}
}
digitalWrite will write LOW if the value is zero and HIGH if the value is 1.
Don't hesitate if you have still questions.
Have fun!
ec2021
(Just to complete the explanation: In your sketch from post #1 timeDelay has to be set to zero in the first if-clause to avoid that the sketch runs immediately into the second if-clause.)