Iterators: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Created Nim solution.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(One intermediate revision by one other user not shown)
Line 118:
dc.b "Purple",0
even</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="AutoHotkey">oDays := ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
oColors := ["Red","Orange","Yellow","Green","Blue","Purple"]
MsgBox % Result := ""
. "All elements:`n" Iterators(oDays) "`n" Iterators(oColors)
. "`n`nFirst, fourth, and fifth:`n" Iterators(oDays, [1,4,5]) "`n" Iterators(oColors, [1,4,5])
. "`n`nReverse first, fourth, and fifth:`n" Iterators(oDays, [1,4,5], 1) "`n" Iterators(oColors, [1,4,5], 1)
return
 
Iterators(obj, num:="", rev:=0){
for i, v in (num.Count() ? num : obj)
res .= (rev ? obj[obj.Count() +1 -v] : num.Count() ? obj[v] : v) ", "
return Trim(res, ", ") "."
}</syntaxhighlight>
{{out}}
<pre>All elements:
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.
Red, Orange, Yellow, Green, Blue, Purple.
 
First, fourth, and fifth:
Sunday, Wednesday, Thursday.
Red, Green, Blue.
 
Reverse first, fourth, and fifth:
Saturday, Wednesday, Tuesday.
Purple, Yellow, Orange.</pre>
 
=={{header|BASIC256}}==
Line 1,339 ⟶ 1,366:
 
The iterator protocol methods are not usually called directly as Wren's 'for' statement (and the Sequence methods) call them automatically under the hood. However, in the spirit of this task, they are called directly.
<syntaxhighlight lang="ecmascriptwren">import "./llist" for DLinkedList
 
// Use iterators to print all elements of the sequence.
9,476

edits