Use the lists:map, lists:foldl, lists:foldr, or lists:foreach functions if you have a known list of (possibly non-contiguous) integers. Otherwise, try a do loop.
For example, to double all entries in a list:
4> lists:filter(fun (X) -> case X rem 2 of
4> 0 -> true;
4> _ -> false
4> end
4> end, lists:seq(0,72,1)).
[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,
32,34,36,38,40,42,44,46,48,50,52,54,56|...]
Of course, if you know you want evens, it's easy enough just
to do this:
Erlang forces you into a more functional approach to loops, since it does not provide normal looping constructs of an imperitive programming language.
The following code shows each technique, (plus recursion). Here we only print the numbers we generate: