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?
re @paul1956 @CyrusNajmabadi
I think it was proposed to replace the For loop to handle the edge cases. While i.Inbetween(Byte.Min, Byte.Max, Step:=2) But maybe Adam had something else in mind.
I am just thinking about the clauses used in
Case Statements, to see if I can extract the out in a general pattern matching syntax.
Select Case operand Case min To max Step stepping Case Else End Select
So thinking about a smarter lowering, for the step case.