BGE, logic bricks, setting up a timer (that reverses at some point)
Logic bricks are best explained with an image :



the basic idea is that instead of adding 1 to your “timer” you add an “increment” property.
You then switch this "increment" to -1 when it reaches 4 and back to 1 (effectively +1) again when the “timer” value is back to 0

to switch the "increment" property from +1 to -1 I do some fancy math (inverting the value and doubling it)

For a simpler version, you could also do it with 2 separate logic flows like here: