Loops/Foreach: Difference between revisions
Content added Content deleted
m (Added Erlang!) |
|||
Line 200: | Line 200: | ||
In E, the for ... in ... loop is also used for iterating over numeric ranges; see [[Loop/For#E]]. |
In E, the for ... in ... loop is also used for iterating over numeric ranges; see [[Loop/For#E]]. |
||
=={{header|Erlang}}== |
|||
Any data structure can be printed as a whole, preformated: |
|||
<lang erlang>io:format("~p~n",[Collection]).</lang> |
|||
However, to iterate over each element of a list, Erlang uses <tt>lists:map/2</tt>, except in the case of IO where <tt>lists:foreach/2</tt> has to be used as the evaluation order is defined to be the same as the order of the elements in the list. |
|||
<lang erlang>lists:foreach(fun(X) -> io:format("~p~n",[X]) end, Collection).</lang> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |