distance counting programming

what i need is how to program an arduino for distance counting to count up only when the value is above 50 then go back to below 50.

if (value<50){
led light up;
}

else(value>50){

}

only count up when after going above 50 and back to below 50

Can any1 help me.

Thanks in advance

// count up only when the value is above 50 then go back to below 50.
boolean above50 = value > 50;
boolean below50 = value < 50;
static boolean previouslyAbove50 = false;
static int distance = 0;
if (below50 && previouslyAbove50) {
    distance++;
    previouslyAbove50 = false;
}
if (above50) {
    previouslyAbove50 = true;
}