# [erlang-questions] How would you do 100 ifs?

Torben Hoffmann <>
Tue Nov 15 14:43:52 CET 2011

```I would assume that inifinity is 10,000,000 (that is a pretty big
number, if it is not enough you can just use X * 10,000,000 as infinity)
and then I would create a dict and store an index for each number
between 0 and 10,000,000 based on the index in the list and then look up
the value for X in the dict.

Something like this:

{_,Lookup} = lists:foldl( fun(Ls,{Index,Dict}) ->
NewDict = lists:foldl( fun(L,
D) -> dict:store(L,Index,D) end,
Dict,
Ls),
{Index+1, NewDict}
end,
{0, dict:new()},
ListOfRanges),
dict:find(X,Lookup).

But bear with me I have not given this much thought let alone pushed
through the compiler.

Cheers,
Torben

On 15/11/11 14:27 , Max Bourinov wrote:
> Hi guys,
>
> I have a value X which is integer, and I have a list of ranges
> [0....200),[200....600),[600...1000)....etc....[100000, infinity]
> (this is just an example). We can assume that the list is static.
>
> I have frequently check the index of the range X belongs to.
> How would you implement it in Erlang?
>
> Best regards,
> Max
>
>
> _______________________________________________
> erlang-questions mailing list
>
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111115/d6ba6cba/attachment.html>
```