I want to fairly efficiently to check if a value, is within two bounds but that range isn't continuous but has a regular stepping.
start := 0, finish := 10, stepping:= 2' Ifvalue:=2
then return true. Ifvalue=7` return false.
The following works, assuming we if pass in arguments that satisfies the for loop conditions.
Function IsBetween(value as Integer, start As Integer, finish As Integer, stepping As Integer ) As Boolean For index = start To finish Step stepping If index = value Then Return True Next Return False End Function
But it is rather inefficient, since we could check if a value is within some bounds simply using
Math.Min(start, finish) <= value and value<=Math.Max(start, finish). But this doesn't take into account a stepping. My question is, "Is there an efficient way to do that?"
(value - start) % step == 0?