Help On If Statement!!

A quick question:

If i have a while loop which looks for totals and if two totals don't match then output a message in an email as a warning, this loop goes round four times.

I want to only email the person if a set of figures does not match. to do this i was going to put it in an if statement after the while loop. see below:

if [ $ATTENTION = ON ]
then
#email all users
mailx -r $MAIL_FROM -s "xxxxx Counts WARNING: ERROR CHECK" $EMAIL < $MSG_DEST
fi

the problem is during the loop the first set of data might set $ATTENTION to ON but the rest might be off. When i echo the $ATTENTION it says OFF so the above loop does not work. So what do i want to do is basically say if $ATTENTION is at any time set to ON then email??

how can this be done?

Please show the code where you set the variable $ATTENTION.

I have now sorted the issue, Thanks anyway jyoung for replying to this. I set functions up and created a variable in there and used that variable to send the email or not within the script:

function set outside the script:

count_1_error()

{
if [ $cnt_mem -lt $previous_mem ]
then
ATTENTION="YES: WARNING CHECK DATA"
ATTENTION_REQUIRED="ON"
fi

}

count_error()

within the script:

if [ "$ATTENTION_REQUIRED" = "ON" ]
then
#email all users
mailx -r $MAIL_FROM -s "xxxxxxxxx Counts WARNING: ERROR CHECK" $EMAIL < $MSG_DEST

fi

rm $MSG_DEST