Loops/Foreach: Difference between revisions
Content deleted Content added
Childishbeat (talk | contribs) m →{{header|NS-HUBASIC}}: NS-HUBASIC example added |
Add LIL |
||
Line 1,373: | Line 1,373: | ||
5 iota >>say.</lang> |
5 iota >>say.</lang> |
||
=={{header|LIL}}== |
|||
<lang tcl># Loops/Foreach, in LIL |
|||
set collection [list 1 2 "three"] |
|||
append collection [list 4 5 six] # appended as a single item in collection |
|||
print "Collection is: $collection" |
|||
# using default "i" variable name set for each item |
|||
foreach $collection {print $i} |
|||
# user named variable in the steps, retrieving accumulated result of loop |
|||
# each loop step quotes two copies of the item |
|||
set newlist [foreach j $collection {quote $j $j}] |
|||
print "Result of second foreach: $newlist"</lang> |
|||
{{out}} |
|||
<pre>prompt$ lil loopsForeach.lil |
|||
Collection is: 1 2 three {4 5 six} |
|||
1 |
|||
2 |
|||
three |
|||
4 5 six |
|||
Result of second foreach: {1 1} {2 2} {three three} {4 5 six 4 5 six}</pre> |
|||
=={{header|Lingo}}== |
=={{header|Lingo}}== |