How to remain inside a function?

But isn't that what the next 2 IF statements do? Test in the 0-4 seconds for the max value and test in 4-8 seconds for the min value?