Loop with condition

i dont want it to turn off, when there is no 5V, the display should freeze whatever it was showing and resume back when 5v is received...basically this project is to count downtime of a machine