LOOKUPZ(Index: v1, v2..v3, etc) : Value what are ranges?
Bob Drury
Posts: 236
in Propeller 2
LOOKUPZ(Index: v1, v2..v3, etc) : Value
Lookup value (values and ranges allowed) using 1-based index, return value (0 if index out of range)
What are ranges?
Regards and Thanks
Bob (WRD)
Comments
An example of a range is 12..25 meaning all of the values between 12 and 25 inclusive.
x := 150
a := 100
b := 300
w := lookup(x: A..B) '
debug(udec(x),udec(y),udec(w) 'w= 249
x := 50
a := 100
b := 300
w := lookup(x: A..B)
debug(udec(x),udec(y),udec(w)) 'w= 149
x := 2
a := 100
b := 300
w := lookup(x: A..B)
debug(udec(x),udec(y),udec(w)) 'w=101
If lookupz used instead of lookup the result for above is 250,150,102 not sure how this would ever be used?
The lookup functions tend to be used to convert a contiguous range to a non-contiguous range -- the lookupz variant changes the offset of the first element of the list. This example makes that easy to see:
The output:
With lookup the search value of zero can be thought of as "don't convert" when used like this:
In this case if x is 0 it won't be converted. That said, it can be simplified like this
In either case, if x is zero it won't be modified, otherwise it will get set to the xth position within the range of a..b.
thanks i wasn't getting the index to position and i see you can also use arrays within the lookup
that is a new one for me
cool,
Mike