Questions on programming logic? So I am learning arduino code by going through examples and playing with them, and I came across something interesting. I am not fluent in any coding language but I am fully familiarized with computer logic and function so I can read what you suggest just fine. 

What I want to know is, why are these two code pieces different? 

const int ledPin =  13;     

int ledState = LOW;            

long interval = 1000;          

void setup() {

pinMode(ledPin, OUTPUT);      
}

void loop()
{

  unsigned long currentMillis = millis();

  if(currentMillis &gt; interval) {

    currentMillis = 0;  


    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;


    digitalWrite(ledPin, ledState);
  }
}


This is my code, or rather modification to this code: 

const int ledPin =  13;     


int ledState = LOW;           
long previousMillis = 0;      


long interval = 1000;      

void setup() {

  pinMode(ledPin, OUTPUT);      
}

void loop()
{

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis &gt; interval) {

    previousMillis = currentMillis;   

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    digitalWrite(ledPin, ledState);
  }

}


How is it that the first code works, and the second code turns the led on and either terminates or never turns the LED off? The code is designed to blink the LED once every 1 second.
Ah yes, this problem.

Note the declaration of currentMillis:

unsigned long currentMillis = ...;


And now note the declaration of previousMillis:

long previousMillis = ...;


You wouldn't think that one little word could make that much difference, but it does. It completely changes how C performs mathematics. previousMillis must also be unsigned or you will get undesired results.