Syntax for stopping loop until the condition has made false
Your code doesn't make sense. You have a while (1) statement, which will run forever. Inside the body of that statement, you never change the value of temp.

An Arduino sketch's loop() function runs continuously. You should not have a while (1) loop inside your loop function. You should have a loop function something like this:

void loop() {
  temp = //read a temp value somehow 
  if(temp&gt;=0&amp;&amp;temp&lt;=20)
  {
    digitalWrite(2,HIGH);
  }
  else if (temp&gt;=20&amp;&amp;temp&lt;=30)
  {
    digitalWrite(1,HIGH);
    digitalWrite(3,HIGH);
    digitalWrite(1,LOW);
  }
}   


With that loop function you would fetch a new value of temp on each pass through the loop, then decide what LEDs to light.