Help programming ATtiny85 for clap on clap off light switch

I am new to the arduino, but I am an intermediate programmer, java, c++, python, c#, and have always been very interested in electronics. I have been planning out this circuit for a few days, linked below, and have had it verified that it would work(on the hardware end, i am making a post here for the code), so long as the ATTiny85 was programmed correctly. I have looked at some code for clap on clap off lights, but they are for LEDs, not Relays, and I was wondering if somebody could help me adapt the code to my purposes. Looking at the circuit attatched, the AC current powers the power supply which powers the attiny, mic, and relay. When the mic hears a clap, a signal is sent across the relay into an input pin on the attiny. The attiny will then output that to the relay, which takes the live wire in and live wire out, and will toggle the connection. Again, you can look at the circuit below, and I will also have the code below, thanks in advance.

const int buttonPin = 2;
const int ledPin = 0;

int buttonstate = 0;
int ledstate = 0;

void setup() {

pinMode(ledPin, OUTPUT);

pinMode(buttonPin, INPUT);
}

void loop(){

buttonstate = digitalRead(buttonPin);
ledstate = digitalRead(ledPin);

if (ledstate == HIGH && buttonstate == LOW) {
delay(250);
digitalWrite(ledPin, LOW);
}
if (ledstate == LOW && buttonstate == LOW) {
delay(250);
digitalWrite(ledPin, HIGH);
}
}

I'm having a similar problem. And actually it didn't workout well for me yet but I've witnessed better feedback. Try using a do...while statement. And don't forget to declare your condition values inside the {}.

HadiHissi: I'm having a similar problem. And actually it didn't workout well for me yet but I've witnessed better feedback. Try using a do...while statement. And don't forget to declare your condition values inside the {}.

Do you think you could explain more, I'm a good programmer but don't know much about microcontrollers. Do what while what, and go in depth plz.

Bump