Kevin that expression work is formidable. Really good stuff.
whilst messing around with the expression to understand how it works I found you can reduce your code slightly into this…
if (time < key(1).time) loopIn(“continue”);
else (value);
if (time > key(numKeys).time) loopOut(“continue”);