A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
1
Task/Loops-Foreach/0DESCRIPTION
Normal file
1
Task/Loops-Foreach/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
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.
|
||||
2
Task/Loops-Foreach/1META.yaml
Normal file
2
Task/Loops-Foreach/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Iteration
|
||||
5
Task/Loops-Foreach/ACL2/loops-foreach.acl2
Normal file
5
Task/Loops-Foreach/ACL2/loops-foreach.acl2
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun print-list (xs)
|
||||
(if (endp xs)
|
||||
nil
|
||||
(prog2$ (cw "~x0~%" (first xs))
|
||||
(print-list (rest xs)))))
|
||||
5
Task/Loops-Foreach/ALGOL-68/loops-foreach.alg
Normal file
5
Task/Loops-Foreach/ALGOL-68/loops-foreach.alg
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[]UNION(STRING, INT, PROC(REF FILE)VOID) collection = ("Mary","Had",1,"little","lamb.",new line);
|
||||
|
||||
FOR index FROM LWB collection TO UPB collection DO
|
||||
print((collection[index]," "))
|
||||
OD
|
||||
6
Task/Loops-Foreach/AWK/loops-foreach-1.awk
Normal file
6
Task/Loops-Foreach/AWK/loops-foreach-1.awk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN {
|
||||
split("Mary had a little lamb", strs, " ")
|
||||
for(el in strs) {
|
||||
print strs[el]
|
||||
}
|
||||
}
|
||||
3
Task/Loops-Foreach/AWK/loops-foreach-2.awk
Normal file
3
Task/Loops-Foreach/AWK/loops-foreach-2.awk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
for(i=1; i <= length(strs); i++) {
|
||||
print strs[i]
|
||||
}
|
||||
5
Task/Loops-Foreach/AWK/loops-foreach-3.awk
Normal file
5
Task/Loops-Foreach/AWK/loops-foreach-3.awk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# This will not work
|
||||
BEGIN {
|
||||
for (l in "apples","bananas","cherries") {
|
||||
print "I like " l
|
||||
}
|
||||
14
Task/Loops-Foreach/Ada/loops-foreach-1.ada
Normal file
14
Task/Loops-Foreach/Ada/loops-foreach-1.ada
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
with Ada.Integer_Text_IO;
|
||||
use Ada.Integer_Text_IO;
|
||||
|
||||
procedure For_Each is
|
||||
|
||||
A : array (1..5) of Integer := (-1, 0, 1, 2, 3);
|
||||
|
||||
begin
|
||||
|
||||
for Num in A'Range loop
|
||||
put( A (Num) );
|
||||
end loop;
|
||||
|
||||
end For_Each;
|
||||
25
Task/Loops-Foreach/Ada/loops-foreach-2.ada
Normal file
25
Task/Loops-Foreach/Ada/loops-foreach-2.ada
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
with Ada.Integer_Text_IO, Ada.Containers.Doubly_Linked_Lists;
|
||||
use Ada.Integer_Text_IO, Ada.Containers;
|
||||
|
||||
procedure Doubly_Linked_List is
|
||||
|
||||
package DL_List_Pkg is new Doubly_Linked_Lists (Integer);
|
||||
use DL_List_Pkg;
|
||||
|
||||
procedure Print_Node (Position : Cursor) is
|
||||
begin
|
||||
Put (Element (Position));
|
||||
end Print_Node;
|
||||
|
||||
DL_List : List;
|
||||
|
||||
begin
|
||||
|
||||
DL_List.Append (1);
|
||||
DL_List.Append (2);
|
||||
DL_List.Append (3);
|
||||
|
||||
-- Iterates through every node of the list.
|
||||
DL_List.Iterate (Print_Node'Access);
|
||||
|
||||
end Doubly_Linked_List;
|
||||
25
Task/Loops-Foreach/Ada/loops-foreach-3.ada
Normal file
25
Task/Loops-Foreach/Ada/loops-foreach-3.ada
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
with Ada.Integer_Text_IO, Ada.Containers.Vectors;
|
||||
use Ada.Integer_Text_IO, Ada.Containers;
|
||||
|
||||
procedure Vector_Example is
|
||||
|
||||
package Vector_Pkg is new Vectors (Natural, Integer);
|
||||
use Vector_Pkg;
|
||||
|
||||
procedure Print_Element (Position : Cursor) is
|
||||
begin
|
||||
Put (Element (Position));
|
||||
end Print_Element;
|
||||
|
||||
V : Vector;
|
||||
|
||||
begin
|
||||
|
||||
V.Append (1);
|
||||
V.Append (2);
|
||||
V.Append (3);
|
||||
|
||||
-- Iterates through every element of the vector.
|
||||
V.Iterate (Print_Element'Access);
|
||||
|
||||
end Vector_Example;
|
||||
4
Task/Loops-Foreach/Aikido/loops-foreach-1.aikido
Normal file
4
Task/Loops-Foreach/Aikido/loops-foreach-1.aikido
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var str = "hello world"
|
||||
foreach ch str { // you can also use an optional 'in'
|
||||
println (ch) // one character at a time
|
||||
}
|
||||
4
Task/Loops-Foreach/Aikido/loops-foreach-2.aikido
Normal file
4
Task/Loops-Foreach/Aikido/loops-foreach-2.aikido
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var vec = [1,2,3,4]
|
||||
foreach v vec { // you can also use an optional 'in'
|
||||
println (v)
|
||||
}
|
||||
4
Task/Loops-Foreach/Aikido/loops-foreach-3.aikido
Normal file
4
Task/Loops-Foreach/Aikido/loops-foreach-3.aikido
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var cities = {"San Ramon": 50000, "Walnut Creek": 70000, "San Francisco": 700000} // map literal
|
||||
foreach city cities {
|
||||
println (city.first + " has population " + city.second)
|
||||
}
|
||||
13
Task/Loops-Foreach/Aikido/loops-foreach-4.aikido
Normal file
13
Task/Loops-Foreach/Aikido/loops-foreach-4.aikido
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
foreach i 100 {
|
||||
println (i) // prints values 0..99
|
||||
}
|
||||
|
||||
foreach i 10..20 {
|
||||
println (i) // prints values 10..20
|
||||
}
|
||||
|
||||
var a = 20
|
||||
var b = 10
|
||||
foreach i a..b {
|
||||
println (i) // prints values from a to b (20..10)
|
||||
}
|
||||
34
Task/Loops-Foreach/Aikido/loops-foreach-5.aikido
Normal file
34
Task/Loops-Foreach/Aikido/loops-foreach-5.aikido
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class List {
|
||||
class Element (public data) {
|
||||
public var next = null
|
||||
}
|
||||
var start = null
|
||||
|
||||
public function insert (data) {
|
||||
var element = new Element (data)
|
||||
element.next = start
|
||||
start = element
|
||||
}
|
||||
|
||||
public operator foreach (var iter) {
|
||||
if (typeof(iter) == "none") { // first iteration
|
||||
iter = start
|
||||
return iter.data
|
||||
} elif (iter.next == null) { // check for last iteration
|
||||
iter = none
|
||||
} else {
|
||||
iter = iter.next // somewhere in the middle
|
||||
return iter.data
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var list = new List()
|
||||
list.insert (1)
|
||||
list.insert (2)
|
||||
list.insert (4)
|
||||
|
||||
foreach n list {
|
||||
println (n)
|
||||
}
|
||||
13
Task/Loops-Foreach/Aikido/loops-foreach-6.aikido
Normal file
13
Task/Loops-Foreach/Aikido/loops-foreach-6.aikido
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// coroutine to generate the squares of a sequence of numbers
|
||||
function squares (start, end) {
|
||||
for (var i = start ; i < end ; i++) {
|
||||
yield i*i
|
||||
}
|
||||
}
|
||||
|
||||
var start = 10
|
||||
var end = 20
|
||||
|
||||
foreach s squares (start, end) {
|
||||
println (s)
|
||||
}
|
||||
4
Task/Loops-Foreach/Aikido/loops-foreach-7.aikido
Normal file
4
Task/Loops-Foreach/Aikido/loops-foreach-7.aikido
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var s = openin ("input.txt")
|
||||
foreach line s {
|
||||
print (line)
|
||||
}
|
||||
7
Task/Loops-Foreach/Aikido/loops-foreach-8.aikido
Normal file
7
Task/Loops-Foreach/Aikido/loops-foreach-8.aikido
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
enum Color {
|
||||
RED, GREEN, BLUE
|
||||
}
|
||||
|
||||
foreach color Color {
|
||||
println (color)
|
||||
}
|
||||
9
Task/Loops-Foreach/AmigaE/loops-foreach.amiga
Normal file
9
Task/Loops-Foreach/AmigaE/loops-foreach.amiga
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
PROC main()
|
||||
DEF a_list : PTR TO LONG, a
|
||||
a_list := [10, 12, 14]
|
||||
FOR a := 0 TO ListLen(a_list)-1
|
||||
WriteF('\d\n', a_list[a])
|
||||
ENDFOR
|
||||
-> if the "action" fits a single statement, we can do instead
|
||||
ForAll({a}, a_list, `WriteF('\d\n', a))
|
||||
ENDPROC
|
||||
3
Task/Loops-Foreach/AutoHotkey/loops-foreach.ahk
Normal file
3
Task/Loops-Foreach/AutoHotkey/loops-foreach.ahk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
string = mary,had,a,little,lamb
|
||||
Loop, Parse, string, `,
|
||||
MsgBox %A_LoopField%
|
||||
7
Task/Loops-Foreach/BASIC256/loops-foreach.basic256
Normal file
7
Task/Loops-Foreach/BASIC256/loops-foreach.basic256
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
DIM collection$(1)
|
||||
collection$ = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog." }
|
||||
|
||||
FOR i = 0 TO collection$[?]-1
|
||||
PRINT collection$[i]+ " ";
|
||||
NEXT i
|
||||
PRINT
|
||||
8
Task/Loops-Foreach/BBC-BASIC/loops-foreach.bbc
Normal file
8
Task/Loops-Foreach/BBC-BASIC/loops-foreach.bbc
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
DIM collection$(8)
|
||||
collection$() = "The", "quick", "brown", "fox", "jumps", \
|
||||
\ "over", "the", "lazy", "dog."
|
||||
|
||||
FOR index% = 0 TO DIM(collection$(), 1)
|
||||
PRINT collection$(index%) " ";
|
||||
NEXT
|
||||
PRINT
|
||||
7
Task/Loops-Foreach/Bracmat/loops-foreach-1.bracmat
Normal file
7
Task/Loops-Foreach/Bracmat/loops-foreach-1.bracmat
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
( list
|
||||
= Afrikaans
|
||||
Ελληνικά
|
||||
עברית
|
||||
മലയാളം
|
||||
ئۇيغۇرچە
|
||||
)
|
||||
2
Task/Loops-Foreach/Bracmat/loops-foreach-2.bracmat
Normal file
2
Task/Loops-Foreach/Bracmat/loops-foreach-2.bracmat
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
!list:?L
|
||||
& whl'(!L:%?language ?L&out$!language)
|
||||
7
Task/Loops-Foreach/Bracmat/loops-foreach-3.bracmat
Normal file
7
Task/Loops-Foreach/Bracmat/loops-foreach-3.bracmat
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
!list:?L
|
||||
& ( loop
|
||||
= !L:%?language ?L
|
||||
& out$!language
|
||||
& !loop
|
||||
)
|
||||
& ~!loop
|
||||
4
Task/Loops-Foreach/Bracmat/loops-foreach-4.bracmat
Normal file
4
Task/Loops-Foreach/Bracmat/loops-foreach-4.bracmat
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
( !list
|
||||
: ? (%@?language&out$!language&~) ?
|
||||
|
|
||||
)
|
||||
4
Task/Loops-Foreach/C++/loops-foreach-1.cpp
Normal file
4
Task/Loops-Foreach/C++/loops-foreach-1.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
for (container_type::iterator i = container.begin(); i != container.end(); ++i)
|
||||
{
|
||||
std::cout << *i << "\n";
|
||||
}
|
||||
2
Task/Loops-Foreach/C++/loops-foreach-2.cpp
Normal file
2
Task/Loops-Foreach/C++/loops-foreach-2.cpp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
std::copy(container.begin(), container.end(),
|
||||
std::output_iterator<container_type::value_type>(std::cout, "\n"));
|
||||
7
Task/Loops-Foreach/C++/loops-foreach-3.cpp
Normal file
7
Task/Loops-Foreach/C++/loops-foreach-3.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
void print_element(container_type::value_type const& v)
|
||||
{
|
||||
std::cout << v << "\n";
|
||||
}
|
||||
|
||||
...
|
||||
std::for_each(container.begin(), container.end(), print_element);
|
||||
6
Task/Loops-Foreach/C++/loops-foreach-4.cpp
Normal file
6
Task/Loops-Foreach/C++/loops-foreach-4.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <iterator_concepts>
|
||||
|
||||
for (auto element: container)
|
||||
{
|
||||
std::cout << element << "\n";
|
||||
}
|
||||
6
Task/Loops-Foreach/C++/loops-foreach-5.cpp
Normal file
6
Task/Loops-Foreach/C++/loops-foreach-5.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <iterator_concepts>
|
||||
|
||||
for (auto const& element: container)
|
||||
{
|
||||
std::cout << element << "\n";
|
||||
}
|
||||
10
Task/Loops-Foreach/C/loops-foreach-1.c
Normal file
10
Task/Loops-Foreach/C/loops-foreach-1.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
...
|
||||
|
||||
const char *list[] = {"Red","Green","Blue","Black","White"};
|
||||
#define LIST_SIZE (sizeof(list)/sizeof(list[0]))
|
||||
|
||||
int ix;
|
||||
for(ix=0; ix<LIST_SIZE; ix++) {
|
||||
printf("%s\n", list[ix]);
|
||||
}
|
||||
17
Task/Loops-Foreach/C/loops-foreach-2.c
Normal file
17
Task/Loops-Foreach/C/loops-foreach-2.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/* foreach macro for using a string as a collection of char */
|
||||
#define foreach( ptrvar , strvar ) char* ptrvar; for( ptrvar=strvar ; (*ptrvar) != '\0' ; *ptrvar++)
|
||||
|
||||
int main(int argc,char* argv[]){
|
||||
char* s1="abcdefg";
|
||||
char* s2="123456789";
|
||||
foreach( p1 , s1 ) {
|
||||
printf("loop 1 %c\n",*p1);
|
||||
}
|
||||
foreach( p2 , s2 ){
|
||||
printf("loop 2 %c\n",*p2);
|
||||
}
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
16
Task/Loops-Foreach/C/loops-foreach-3.c
Normal file
16
Task/Loops-Foreach/C/loops-foreach-3.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
int main(int argc,char* argv[]){
|
||||
/* foreach macro viewing an array of int values as a collection of int values */
|
||||
#define foreach( intpvar , intary ) int* intpvar; for( intpvar=intary; intpvar < (intary+(sizeof(intary)/sizeof(intary[0]))) ; intpvar++)
|
||||
int a1[]={ 1 , 1 , 2 , 3 , 5 , 8 };
|
||||
int a2[]={ 3 , 1 , 4 , 1, 5, 9 };
|
||||
foreach( p1 , a1 ) {
|
||||
printf("loop 1 %d\n",*p1);
|
||||
}
|
||||
foreach( p2 , a2 ){
|
||||
printf("loop 2 %d\n",*p2);
|
||||
}
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
24
Task/Loops-Foreach/C/loops-foreach-4.c
Normal file
24
Task/Loops-Foreach/C/loops-foreach-4.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
int main(int argc,char* argv[]){
|
||||
#define foreach( idxtype , idxpvar , col , colsiz ) idxtype* idxpvar; for( idxpvar=col ; idxpvar < (col+(colsiz)) ; idxpvar++)
|
||||
#define arraylen( ary ) ( sizeof(ary)/sizeof(ary[0]) )
|
||||
char* c1="collection";
|
||||
int c2[]={ 3 , 1 , 4 , 1, 5, 9 };
|
||||
double* c3;
|
||||
int c3len=4;
|
||||
c3=(double*)calloc(c3len,sizeof(double));
|
||||
c3[0]=1.2;c3[1]=3.4;c3[2]=5.6;c3[3]=7.8;
|
||||
foreach( char,p1 , c1, strlen(c1) ) {
|
||||
printf("loop 1 : %c\n",*p1);
|
||||
}
|
||||
foreach( int,p2 , c2, arraylen(c2) ){
|
||||
printf("loop 2 : %d\n",*p2);
|
||||
}
|
||||
foreach( double,p3 , c3, c3len ){
|
||||
printf("loop 3 : %3.1lf\n",*p3);
|
||||
}
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
5
Task/Loops-Foreach/CMake/loops-foreach.cmake
Normal file
5
Task/Loops-Foreach/CMake/loops-foreach.cmake
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
set(list one.c two.c three.c)
|
||||
|
||||
foreach(file ${list})
|
||||
message(${file})
|
||||
endforeach(file)
|
||||
1
Task/Loops-Foreach/Clojure/loops-foreach.clj
Normal file
1
Task/Loops-Foreach/Clojure/loops-foreach.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(doseq [item collection] (println item))
|
||||
1
Task/Loops-Foreach/Common-Lisp/loops-foreach-1.lisp
Normal file
1
Task/Loops-Foreach/Common-Lisp/loops-foreach-1.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(loop for i in list do (print i))
|
||||
1
Task/Loops-Foreach/Common-Lisp/loops-foreach-2.lisp
Normal file
1
Task/Loops-Foreach/Common-Lisp/loops-foreach-2.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(map nil #'print list)
|
||||
18
Task/Loops-Foreach/D/loops-foreach.d
Normal file
18
Task/Loops-Foreach/D/loops-foreach.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import std.stdio: writeln;
|
||||
|
||||
void main() {
|
||||
auto collection1 = "ABC";
|
||||
foreach (element; collection1)
|
||||
writeln(element);
|
||||
|
||||
auto collection2 = [1, 2, 3];
|
||||
foreach (element; collection1)
|
||||
writeln(element);
|
||||
|
||||
auto collection3 = [1:10, 2:20, 3:30];
|
||||
foreach (element; collection3)
|
||||
writeln(element);
|
||||
|
||||
foreach (key, value; collection3)
|
||||
writeln(key, " ", value);
|
||||
}
|
||||
2
Task/Loops-Foreach/Dao/loops-foreach.dao
Normal file
2
Task/Loops-Foreach/Dao/loops-foreach.dao
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
items = { 1, 2, 3 }
|
||||
for( item in items ) io.writeln( item )
|
||||
10
Task/Loops-Foreach/Delphi/loops-foreach.delphi
Normal file
10
Task/Loops-Foreach/Delphi/loops-foreach.delphi
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
program LoopForEach;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
s: string;
|
||||
begin
|
||||
for s in 'Hello' do
|
||||
Writeln(s);
|
||||
end.
|
||||
3
Task/Loops-Foreach/E/loops-foreach.e
Normal file
3
Task/Loops-Foreach/E/loops-foreach.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
for e in theCollection {
|
||||
println(e)
|
||||
}
|
||||
1
Task/Loops-Foreach/Efene/loops-foreach-1.efene
Normal file
1
Task/Loops-Foreach/Efene/loops-foreach-1.efene
Normal file
|
|
@ -0,0 +1 @@
|
|||
io.format("~p~n", [Collection])
|
||||
1
Task/Loops-Foreach/Efene/loops-foreach-2.efene
Normal file
1
Task/Loops-Foreach/Efene/loops-foreach-2.efene
Normal file
|
|
@ -0,0 +1 @@
|
|||
lists.foreach(fn (X) { io.format("~p~n", [X]) }, Collection)
|
||||
1
Task/Loops-Foreach/Eiffel/loops-foreach-1.e
Normal file
1
Task/Loops-Foreach/Eiffel/loops-foreach-1.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
across my_list as ic loop print (ic.item) end
|
||||
1
Task/Loops-Foreach/Eiffel/loops-foreach-2.e
Normal file
1
Task/Loops-Foreach/Eiffel/loops-foreach-2.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
across my_list as ic all ic.item.count > 3 end
|
||||
1
Task/Loops-Foreach/Eiffel/loops-foreach-3.e
Normal file
1
Task/Loops-Foreach/Eiffel/loops-foreach-3.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
across my_list as ic some ic.item.count > 3 end
|
||||
3
Task/Loops-Foreach/Ela/loops-foreach-1.ela
Normal file
3
Task/Loops-Foreach/Ela/loops-foreach-1.ela
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
open console imperative
|
||||
|
||||
each writen [1..10]
|
||||
2
Task/Loops-Foreach/Ela/loops-foreach-2.ela
Normal file
2
Task/Loops-Foreach/Ela/loops-foreach-2.ela
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
each f (x::xs) = f x $ each f xs
|
||||
each _ [] = ()
|
||||
3
Task/Loops-Foreach/Ela/loops-foreach-3.ela
Normal file
3
Task/Loops-Foreach/Ela/loops-foreach-3.ela
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
open console list
|
||||
|
||||
_ = map writen [1..10]
|
||||
4
Task/Loops-Foreach/Ela/loops-foreach-4.ela
Normal file
4
Task/Loops-Foreach/Ela/loops-foreach-4.ela
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
each (x::xs) = writen x $ each xs
|
||||
each [] = ()
|
||||
|
||||
each [1..10]
|
||||
1
Task/Loops-Foreach/Erlang/loops-foreach-1.erl
Normal file
1
Task/Loops-Foreach/Erlang/loops-foreach-1.erl
Normal file
|
|
@ -0,0 +1 @@
|
|||
io:format("~p~n",[Collection]).
|
||||
1
Task/Loops-Foreach/Erlang/loops-foreach-2.erl
Normal file
1
Task/Loops-Foreach/Erlang/loops-foreach-2.erl
Normal file
|
|
@ -0,0 +1 @@
|
|||
lists:foreach(fun(X) -> io:format("~p~n",[X]) end, Collection).
|
||||
1
Task/Loops-Foreach/Factor/loops-foreach.factor
Normal file
1
Task/Loops-Foreach/Factor/loops-foreach.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ 1 2 4 } [ . ] each
|
||||
11
Task/Loops-Foreach/Fantom/loops-foreach.fantom
Normal file
11
Task/Loops-Foreach/Fantom/loops-foreach.fantom
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
Int[] collection := [1, 2, 3, 4, 5]
|
||||
collection.each |Int item|
|
||||
{
|
||||
echo (item)
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Task/Loops-Foreach/Forth/loops-foreach.fth
Normal file
3
Task/Loops-Foreach/Forth/loops-foreach.fth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
create a 3 , 2 , 1 ,
|
||||
: .array ( a len -- )
|
||||
cells bounds do i @ . cell +loop ; \ 3 2 1
|
||||
16
Task/Loops-Foreach/Fortran/loops-foreach.f
Normal file
16
Task/Loops-Foreach/Fortran/loops-foreach.f
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
program main
|
||||
|
||||
implicit none
|
||||
|
||||
integer :: i
|
||||
character(len=5),dimension(5),parameter :: colors = ['Red ','Green','Blue ','Black','White']
|
||||
|
||||
!using a do loop:
|
||||
do i=1,size(colors)
|
||||
write(*,'(A)') colors(i)
|
||||
end do
|
||||
|
||||
!this will also print each element:
|
||||
write(*,'(A)') colors
|
||||
|
||||
end program main
|
||||
5
Task/Loops-Foreach/Go/loops-foreach.go
Normal file
5
Task/Loops-Foreach/Go/loops-foreach.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func printAll(values []int) {
|
||||
for i, x := range values {
|
||||
fmt.Printf("Item %d = %d\n", i, x)
|
||||
}
|
||||
}
|
||||
5
Task/Loops-Foreach/Groovy/loops-foreach-1.groovy
Normal file
5
Task/Loops-Foreach/Groovy/loops-foreach-1.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def beatles = ["John", "Paul", "George", "Ringo"]
|
||||
|
||||
for(name in beatles) {
|
||||
println name
|
||||
}
|
||||
3
Task/Loops-Foreach/Groovy/loops-foreach-2.groovy
Normal file
3
Task/Loops-Foreach/Groovy/loops-foreach-2.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
beatles.each {
|
||||
println it
|
||||
}
|
||||
2
Task/Loops-Foreach/Haskell/loops-foreach-1.hs
Normal file
2
Task/Loops-Foreach/Haskell/loops-foreach-1.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import Control.Monad (forM_)
|
||||
forM_ collect print
|
||||
1
Task/Loops-Foreach/Haskell/loops-foreach-2.hs
Normal file
1
Task/Loops-Foreach/Haskell/loops-foreach-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
mapM_ print collect
|
||||
1
Task/Loops-Foreach/Haxe/loops-foreach.haxe
Normal file
1
Task/Loops-Foreach/Haxe/loops-foreach.haxe
Normal file
|
|
@ -0,0 +1 @@
|
|||
for(i in 1...10) Sys.println(i);
|
||||
7
Task/Loops-Foreach/HicEst/loops-foreach.hicest
Normal file
7
Task/Loops-Foreach/HicEst/loops-foreach.hicest
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
CHARACTER days="Monday Tuesday Wednesday Thursday Friday Saturday Sunday "
|
||||
|
||||
items = INDEX(days, ' ', 256) ! 256 = count option
|
||||
DO j = 1, items
|
||||
EDIT(Text=days, ITeM=j, Parse=today)
|
||||
WRITE() today
|
||||
ENDDO
|
||||
5
Task/Loops-Foreach/Icon/loops-foreach-1.icon
Normal file
5
Task/Loops-Foreach/Icon/loops-foreach-1.icon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
procedure main()
|
||||
X := [1,2,3,-5,6,9]
|
||||
every x := !L do
|
||||
write(x)
|
||||
end
|
||||
1
Task/Loops-Foreach/Icon/loops-foreach-2.icon
Normal file
1
Task/Loops-Foreach/Icon/loops-foreach-2.icon
Normal file
|
|
@ -0,0 +1 @@
|
|||
every write(!L)
|
||||
1
Task/Loops-Foreach/Io/loops-foreach.io
Normal file
1
Task/Loops-Foreach/Io/loops-foreach.io
Normal file
|
|
@ -0,0 +1 @@
|
|||
collection foreach(println)
|
||||
1
Task/Loops-Foreach/J/loops-foreach.j
Normal file
1
Task/Loops-Foreach/J/loops-foreach.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
smoutput each i.10
|
||||
5
Task/Loops-Foreach/Java/loops-foreach.java
Normal file
5
Task/Loops-Foreach/Java/loops-foreach.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Iterable<Type> collect;
|
||||
...
|
||||
for(Type i:collect){
|
||||
System.out.println(i);
|
||||
}
|
||||
3
Task/Loops-Foreach/JavaScript/loops-foreach-1.js
Normal file
3
Task/Loops-Foreach/JavaScript/loops-foreach-1.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
for (var a in o) {
|
||||
print(o[a]);
|
||||
}
|
||||
5
Task/Loops-Foreach/JavaScript/loops-foreach-2.js
Normal file
5
Task/Loops-Foreach/JavaScript/loops-foreach-2.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
for (var a in o) {
|
||||
if (o.hasOwnProperty(a)) {
|
||||
print(o[a]);
|
||||
}
|
||||
}
|
||||
14
Task/Loops-Foreach/JavaScript/loops-foreach-3.js
Normal file
14
Task/Loops-Foreach/JavaScript/loops-foreach-3.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
h = {"one":1, "two":2, "three":3}
|
||||
for (x in h) print(x);
|
||||
/*
|
||||
two
|
||||
one
|
||||
three
|
||||
*/
|
||||
|
||||
for each (y in h) print(y);
|
||||
/*
|
||||
2
|
||||
1
|
||||
3
|
||||
*/
|
||||
14
Task/Loops-Foreach/JavaScript/loops-foreach-4.js
Normal file
14
Task/Loops-Foreach/JavaScript/loops-foreach-4.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
h = {"one":1, "two":2, "three":3}
|
||||
for (x in h) print(x);
|
||||
/*
|
||||
two
|
||||
one
|
||||
three
|
||||
*/
|
||||
|
||||
for (y of h) print(y);
|
||||
/*
|
||||
2
|
||||
1
|
||||
3
|
||||
*/
|
||||
1
Task/Loops-Foreach/K/loops-foreach-1.k
Normal file
1
Task/Loops-Foreach/K/loops-foreach-1.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
{`0:$x} ' !10
|
||||
1
Task/Loops-Foreach/K/loops-foreach-2.k
Normal file
1
Task/Loops-Foreach/K/loops-foreach-2.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
_sin ' (1; 2; 3;)
|
||||
2
Task/Loops-Foreach/Lang5/loops-foreach.lang5
Normal file
2
Task/Loops-Foreach/Lang5/loops-foreach.lang5
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
: >>say.(*) . ;
|
||||
5 iota >>say.
|
||||
12
Task/Loops-Foreach/Liberty-BASIC/loops-foreach.liberty
Normal file
12
Task/Loops-Foreach/Liberty-BASIC/loops-foreach.liberty
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
in$ ="Not,Hardly,Just,Adequately,Quite,Really,Very,Fantastically,xyzzy"
|
||||
element$ =""
|
||||
i =1 ' used to point to successive elements
|
||||
|
||||
do
|
||||
element$ =word$( in$, i, ",")
|
||||
if element$ ="xyzzy" then exit do
|
||||
print element$; " good!"
|
||||
i =i +1
|
||||
loop until 1 =2
|
||||
|
||||
end
|
||||
4
Task/Loops-Foreach/Lisaac/loops-foreach.lisaac
Normal file
4
Task/Loops-Foreach/Lisaac/loops-foreach.lisaac
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"Lisaac loop foreach".split.foreach { word : STRING;
|
||||
word.print;
|
||||
'\n'.print;
|
||||
};
|
||||
1
Task/Loops-Foreach/Logo/loops-foreach.logo
Normal file
1
Task/Loops-Foreach/Logo/loops-foreach.logo
Normal file
|
|
@ -0,0 +1 @@
|
|||
foreach [red green blue] [print ?]
|
||||
4
Task/Loops-Foreach/Lua/loops-foreach-1.lua
Normal file
4
Task/Loops-Foreach/Lua/loops-foreach-1.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
t={monday=1, tuesday=2, wednesday=3, thursday=4, friday=5, saturday=6, sunday=0, [7]="fooday"}
|
||||
for key, value in pairs(t) do
|
||||
print(value, key)
|
||||
end
|
||||
4
Task/Loops-Foreach/Lua/loops-foreach-2.lua
Normal file
4
Task/Loops-Foreach/Lua/loops-foreach-2.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
l={'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', not_a_number='fooday', [0]='today', [-1]='yesterday' }
|
||||
for key, value in ipairs(l) do
|
||||
print(key, value)
|
||||
end
|
||||
4
Task/Loops-Foreach/MATLAB/loops-foreach-1.m
Normal file
4
Task/Loops-Foreach/MATLAB/loops-foreach-1.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
list1 = [1,5,6,7,-7,-9];
|
||||
for k = list1, % list1 must be a row vector (i.e. array of size 1xn)
|
||||
printf('%i\n',k)
|
||||
end;
|
||||
4
Task/Loops-Foreach/MATLAB/loops-foreach-2.m
Normal file
4
Task/Loops-Foreach/MATLAB/loops-foreach-2.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
list2 = {'AA','BB','CC'};
|
||||
for k = list2, % list2 must be a row vector (i.e. array of size 1xn)
|
||||
printf('%s\n',k{1})
|
||||
end;
|
||||
2
Task/Loops-Foreach/MATLAB/loops-foreach-3.m
Normal file
2
Task/Loops-Foreach/MATLAB/loops-foreach-3.m
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
printf('%d\n',list1);
|
||||
printf('%s\n',list2{:});
|
||||
4
Task/Loops-Foreach/MAXScript/loops-foreach.max
Normal file
4
Task/Loops-Foreach/MAXScript/loops-foreach.max
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
for i in collect do
|
||||
(
|
||||
print i
|
||||
)
|
||||
5
Task/Loops-Foreach/MOO/loops-foreach.moo
Normal file
5
Task/Loops-Foreach/MOO/loops-foreach.moo
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
things = {"Apple", "Banana", "Coconut"};
|
||||
|
||||
for thing in (things)
|
||||
player:tell(thing);
|
||||
endfor
|
||||
5
Task/Loops-Foreach/Mathematica/loops-foreach.mathematica
Normal file
5
Task/Loops-Foreach/Mathematica/loops-foreach.mathematica
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
s = (StringSplit@Import["ExampleData/USConstitution.txt"])[[1;;7]];
|
||||
Do[
|
||||
Print@i,
|
||||
{i, s}
|
||||
]
|
||||
1
Task/Loops-Foreach/Maxima/loops-foreach.maxima
Normal file
1
Task/Loops-Foreach/Maxima/loops-foreach.maxima
Normal file
|
|
@ -0,0 +1 @@
|
|||
for n in [2, 3, 5, 7] do print(n);
|
||||
2
Task/Loops-Foreach/Metafont/loops-foreach-1.metafont
Normal file
2
Task/Loops-Foreach/Metafont/loops-foreach-1.metafont
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for x = "mary", "had", "a", "little", "lamb": message x; endfor
|
||||
end
|
||||
2
Task/Loops-Foreach/Metafont/loops-foreach-2.metafont
Normal file
2
Task/Loops-Foreach/Metafont/loops-foreach-2.metafont
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for x = for i = 1 upto 9: a[i], endfor, a[10]: show x; endfor
|
||||
end
|
||||
7
Task/Loops-Foreach/PHP/loops-foreach.php
Normal file
7
Task/Loops-Foreach/PHP/loops-foreach.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
foreach ($collect as $i) {
|
||||
echo "$i\n";
|
||||
}
|
||||
|
||||
foreach ($collect as $key => $i) {
|
||||
echo "\$collect[$key] = $i\n";
|
||||
}
|
||||
3
Task/Loops-Foreach/Perl/loops-foreach-1.pl
Normal file
3
Task/Loops-Foreach/Perl/loops-foreach-1.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foreach my $i (@collection) {
|
||||
print "$i\n";
|
||||
}
|
||||
1
Task/Loops-Foreach/Perl/loops-foreach-2.pl
Normal file
1
Task/Loops-Foreach/Perl/loops-foreach-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
print "$_\n" foreach @collection
|
||||
3
Task/Loops-Foreach/Perl/loops-foreach-3.pl
Normal file
3
Task/Loops-Foreach/Perl/loops-foreach-3.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foreach $l ( "apples", "bananas", "cherries" ) {
|
||||
print "I like $l\n";
|
||||
}
|
||||
1
Task/Loops-Foreach/PicoLisp/loops-foreach.l
Normal file
1
Task/Loops-Foreach/PicoLisp/loops-foreach.l
Normal file
|
|
@ -0,0 +1 @@
|
|||
(mapc println '(Apple Banana Coconut))
|
||||
2
Task/Loops-Foreach/Python/loops-foreach-1.py
Normal file
2
Task/Loops-Foreach/Python/loops-foreach-1.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for i in collection:
|
||||
print i
|
||||
10
Task/Loops-Foreach/Python/loops-foreach-2.py
Normal file
10
Task/Loops-Foreach/Python/loops-foreach-2.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
lines = words = characters = 0
|
||||
f = open('somefile','r')
|
||||
for eachline in f:
|
||||
lines += 1
|
||||
for eachword in eachline.split():
|
||||
words += 1
|
||||
for eachchar in eachword:
|
||||
chracters += 1
|
||||
|
||||
print lines, words, characters
|
||||
2
Task/Loops-Foreach/R/loops-foreach.r
Normal file
2
Task/Loops-Foreach/R/loops-foreach.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a <- list("First", "Second", "Third", 5, 6)
|
||||
for(i in a) print(i)
|
||||
6
Task/Loops-Foreach/REXX/loops-foreach.rexx
Normal file
6
Task/Loops-Foreach/REXX/loops-foreach.rexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
days = 'zuntik montik dinstik mitvokh donershtik fraytik shabes'
|
||||
|
||||
do j=1 for words(days) /*loop through days of the week. */
|
||||
say word(days,j) /*display the weekday to screen. */
|
||||
end /*j*/
|
||||
lang postscript> /*stick a fork in it, we're done.*/
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue