Loops/Foreach: Difference between revisions

(Added ColdFusion)
Line 601:
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|Euphoria}}==
{{works with|OpenEuphoria}}
<lang>
include std/console.e
 
sequence s = {-2,-1,0,1,2} --print elements of a numerical list
for i = 1 to length(s) do
? s[i]
end for
 
puts(1,'\n')
 
s = {"Name","Date","Field1","Field2"} -- print elements of a list of 'strings'
for i = 1 to length(s) do
printf(1,"%s\n",{s[i]})
end for
 
puts(1,'\n')
 
for i = 1 to length(s) do -- print subelements of elements of a list of 'strings'
for j = 1 to length(s[i]) do
printf(1,"%s\n",s[i][j])
end for
puts(1,'\n')
end for
 
if getc(0) then end if
</lang>
{{out}}
<pre>
-2
-1
0
1
2
 
Name
Date
Field1
Field2
 
N
a
m
e
 
D
a
t
e
 
F
i
e
l
d
1
 
F
i
e
l
d
2
</pre>
 
=={{header|Factor}}==
Anonymous user