Need help in EEPROM

if i use this code it works

EEPROM.write(0, state);

but this above code can wear by chip out.
soo instead i made this code..but does not work

if (state != lastState) {
  EEPROM.write(0, state);
  lastState = state;

Hi @boopesh_boo ,

What's not working?
Does it give compilation error?
Don't load the sketch?
Does not record?
Writes wrong?
Lock the microcontroller?
Does the chip heat up?
Don't turn on the Arduino?

A "{" is missing at the end of the if.

As Tutankhamun said in 1340 AD, "good help depends on good information".

Read: How to get the best out of this forum

RV mineirin

if( != state)
  EEPROM.write(0, state);
EEPROM.update(0, state);