June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,4 +1,20 @@
|
|||
Loop through and print each element in a collection in order.
|
||||
|
||||
Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop.
|
||||
|
||||
|
||||
;Related tasks:
|
||||
* [[Loop over multiple arrays simultaneously]]
|
||||
* [[Loops/Break]]
|
||||
* [[Loops/Continue]]
|
||||
* [[Loops/Do-while]]
|
||||
* [[Loops/Downward for]]
|
||||
* [[Loops/For]]
|
||||
* [[Loops/For with a specified step]]
|
||||
* [[Loops/Foreach]]
|
||||
* [[Loops/Increment loop index within loop body]]
|
||||
* [[Loops/Infinite]]
|
||||
* [[Loops/N plus one half]]
|
||||
* [[Loops/Nested]]
|
||||
* [[Loops/While]]
|
||||
<br><br>
|
||||
|
|
|
|||
5
Task/Loops-Foreach/Aime/loops-foreach.aime
Normal file
5
Task/Loops-Foreach/Aime/loops-foreach.aime
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# iterate over a list of integers
|
||||
integer i, v;
|
||||
|
||||
for (i, v in list(2, 3, 5, 7, 11, 13, 17, 18)) {
|
||||
}
|
||||
25
Task/Loops-Foreach/Red/loops-foreach.red
Normal file
25
Task/Loops-Foreach/Red/loops-foreach.red
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
>> blk: ["John" 23 "dave" 30 "bob" 20 "Jeff" 40]
|
||||
>> foreach item blk [print item]
|
||||
John
|
||||
23
|
||||
dave
|
||||
30
|
||||
bob
|
||||
20
|
||||
Jeff
|
||||
40
|
||||
>> foreach [name age] blk [print [name "is" age "years old"]]
|
||||
John is 23 years old
|
||||
dave is 30 years old
|
||||
bob is 20 years old
|
||||
Jeff is 40 years old
|
||||
|
||||
>> forall blk [print blk]
|
||||
John 23 dave 30 bob 20 Jeff 40
|
||||
23 dave 30 bob 20 Jeff 40
|
||||
dave 30 bob 20 Jeff 40
|
||||
30 bob 20 Jeff 40
|
||||
bob 20 Jeff 40
|
||||
20 Jeff 40
|
||||
Jeff 40
|
||||
40
|
||||
Loading…
Add table
Add a link
Reference in a new issue