You don't want to stop the loop! You want it to run fast and often.
Eventually you want it to not change the current state of a LED, but in your case, I rather do not see enough defined states of LEDs.
I want to first ON LED1 then ON LED2 then OFF LED1"
if then
means an amount of time, remember that loop runs fast and does not take time by itself. You will have to notice the starting point in time and compare that with the current time and your desired intervals. (And you do not mention what should happen to LED2 after the second then )
const unsigned int LED1_DURATION=500;
const unsigned int LED3_DURATION=1000;
bool c2 = false; // true while condition2 is met
unsigned long start2; // time when condition2 starts
void loop() {
int temp = analogRead(A0); //read a temp value somehow
if(temp<=20)
{
digitlaWrite(1, LOW);
digitalWrite(2,HIGH);
digitlaWrite(3, LOW);
c2 = false;
}
else if (temp >20 && temp <= 30)
{
digitalWrite(2, LOW);
if (c2 == false) { c2 = true; start2=millis(); } // detect start time
if ((millis() - start2 < LED1_DURATION) ||
(millis() - start2 > LED3_DURATION) )
digitalWrite(1,HIGH);
else digitalWrite(1, LOW);
if ((millis() - start2 > LED1_DURATION) &&
(millis() - start2 < LED3_DURATION) )
digitalWrite(3,HIGH);
else digitalWrite(3,LOW);
}
else
{
digitlaWrite(1, LOW);
digitalWrite(2, LOW);
digitlaWrite(3, LOW);
c2 = false;
}
}
This code contains a couple of guesses about states you did not mention, and a slightly different behavior (sorry), but I hope you get an idea...