Using timers and counters.

Lots of ways to implement a counter:
int i = 0;
i = i + 1; // Increase counter by 1
i += 1; // Increase counter by 1
i++; // Increase counter by 1

For a timer:
unsigned long startTime = millis();

if (millis() - startTime > 5000) // 5-second timer has expired
{
}