how to send Alert and avoid doing it second time (loop)?

i am missing something i guess sorry
i tried this code but it is not working

boolean prevState;;
boolean alarm = false;
int myreturn = 0;
uint32_t lastSMS = 0;
uint32_t threshold = 0;
void setup()
{
Serial.begin(9600);
pinMode(3, INPUT); //get the status of electricity 1/0
pinMode(6, OUTPUT); //LED to change on status
prevState= getElectricityStateOK(); // init
}

void loop()
{
boolean stateOK = getElectricityStateOK(); // you know how to do that

if (stateOK != 1) // there is an alarm state
{
if (millis() - lastSMS > threshold) sendSMS(); // send an SMS every threshold milliseconds. // the threshhold gave me an error so i defined it above
lastSMS = millis();

if (prevState != stateOK) // has state changed since last time?
{
alarm = true;
// ... do additional things when alarm goes of here (only one)

}
// do things here while in alarm state ... every loop...
// you mean to say i must include all the code inside this section ?
}
else
{
// reset the alarm
alarm = false;
}
prevState = stateOK ; // remember the last state

// rest of the program
** //or do you mean all the program here ?**
if (alarm) digitalWrite(6, HIGH);
else digitalWrite(6, LOW);

delay(3000);

}

int getElectricityStateOK() {
Serial.println("getting electric state function triggered");
myreturn = digitalRead(5);
return myreturn;

}
void sendSMS(){
Serial.println("send sms function triggered");
}

the above code as tested doesn't work i tried to set the input 3 low high no use... i do not know why the led didn't even started.... sorry for ignorance... it is too much info to chew for me....