langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,4 @@
def things = ["Apple", "Banana", "Coconut"];
foreach (thing in things) WriteLine(thing.ToLower());
foreach (i in [5, 10 .. 100]) Write($"$i\t");

View file

@ -0,0 +1,13 @@
/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
say
say 'Loops/Foreach'
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
daysl = Arrays.asList(days)
daysi = daysl.iterator
loop while daysi.hasNext
say daysi.next
end

View file

@ -0,0 +1,6 @@
var list: seq[string] = @[]
list.add("lorem")
list.add("ipsum")
list.add("dolor")
for i in items(list):
echo(i)

View file

@ -0,0 +1,3 @@
List.iter
(fun i -> Printf.printf "%d\n" i)
collect_list

View file

@ -0,0 +1,3 @@
Array.iter
(fun i -> Printf.printf "%d\n" i)
collect_array

View file

@ -0,0 +1,4 @@
fruits := ["Apple", "Banana", "Coconut"];
each(i : fruits) {
fruits[i]->PrintLine();
};

View file

@ -0,0 +1,5 @@
NSArray *collect;
//...
for(Type i in collect){
NSLog(@"%@", i);
}

View file

@ -0,0 +1,7 @@
NSArray *collect;
//...
NSEnumerator *enm = [collect objectEnumerator];
id i;
while( (i = [enm nextObject]) ) {
// do something with object i
}

View file

@ -0,0 +1,8 @@
a = [ 1,4,3,2 ];
b = [ 1,2,3,4; 5,6,7,8 ];
for v = a
disp(v); % output single values: 1,4,3,2
endfor
for v = b
disp(v); % v is the column vector [1;5], then [2;6] ...
endfor

View file

@ -0,0 +1,6 @@
x.a = [ 10, 11, 12 ];
x.b = { "Cell", "ul", "ar" };
for [ val, key ] = x
disp(key);
disp(val);
endfor

View file

@ -0,0 +1,7 @@
declare
MyList = [1 2 3 4]
in
{ForAll MyList Show}
%% or:
for E in MyList do {Show E} end

View file

@ -0,0 +1 @@
for(i=1,#v,print(v[i]))

View file

@ -0,0 +1 @@
apply(x->print(x),v)

View file

@ -0,0 +1,4 @@
declare A(10) fixed binary;
do i = lbound(A,1) to hbound(A,1);
put skip list (A(i));
end;

View file

@ -0,0 +1 @@
say $_ for @collection;

View file

@ -0,0 +1 @@
for @collection -> $currentElement { say $currentElement; }

View file

@ -0,0 +1,6 @@
int main(){
array(int|string) collect = ({109, "Hi", "asdf", "qwerty"});
foreach(collect, int|string elem){
write(elem + "\n");
}
}

View file

@ -0,0 +1,6 @@
int main(){
mapping(string:string) coll = (["foo":"asdf", "bar":"qwer", "quux":"zxcv"]);
foreach (coll;string key;string val)
write(key+" --> "+val+"\n");
}
}

View file

@ -0,0 +1,4 @@
lvars el, lst = [1 2 3 4 foo bar];
for el in lst do
printf(el,'%p\n');
endfor;

View file

@ -0,0 +1,2 @@
[1 5 3 2] { = } forall
(abc) { = } forall

View file

@ -0,0 +1,6 @@
<</a 25 /b 42>> {
exch (Key: ) print
=
(Value: ) print
=
} forall

View file

@ -0,0 +1,3 @@
foreach ($x in $collection) {
Write-Host $x
}

View file

@ -0,0 +1,3 @@
ForEach element()
PrintN(element())
Next

View file

@ -0,0 +1,15 @@
REBOL [
Title: "Loop/Foreach"
Author: oofoe
Date: 2009-12-19
URL: http://rosettacode.org/wiki/Loop/Foreach
]
x: [Sork Gun Blues Neds Thirst Fright Catur]
foreach i x [prin rejoin [i "day "]] print ""
; REBOL also has the 'forall' construct, which provides the rest of
; the list from the current position.
forall x [prin rejoin [x/1 "day "]] print ""

View file

@ -0,0 +1,15 @@
( Strings: this will display the ASCII code for each character in a string )
"This is a message" [ @ putn space ] ^types'STRING each@
( Array: display each element )
needs array'
[ 1 2 3 ] ^array'fromQuote [ @ putn space ] ^types'ARRAY each@
( Linked List: using the dictionary as an example, display each name )
last [ d->name puts space ] ^types'LIST each@
( Generic Buffers; display each value in a buffer )
create foo
1 , 3 , 5 ,
foo 3 [ @ putn space ] ^types'BUFFER each@

View file

@ -0,0 +1,6 @@
t$={Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
while word$(t$,i+1,",") <> ""
i = i + 1
print word$(t$,i,",")
wend

View file

@ -0,0 +1,11 @@
/* Initialize an array with integers 1 to 10, and print their sum */
data _null_;
array a a1-a10;
n=1;
do over a;
a=n;
n=n+1;
end;
s=sum(of a{*});
put s;
run;

View file

@ -0,0 +1,2 @@
iterate (x; ["Red", "Green", "Blue"])
x!;

View file

@ -0,0 +1,12 @@
$ include "seed7_05.s7i";
var array string: things is [] ("Apple", "Banana", "Coconut");
const proc: main is func
local
var string: thing is "";
begin
for thing range things do
writeln(thing);
end for;
end func;

View file

@ -0,0 +1 @@
c do: [| :obj | print: obj].

View file

@ -0,0 +1,3 @@
app
(fn i => print (Int.toString i ^ "\n"))
collect_list

View file

@ -0,0 +1,3 @@
Array.app
(fn i => print (Int.toString i ^ "\n"))
collect_array

View file

@ -0,0 +1,2 @@
for i in #(1, 2, 3)
Print(i)

View file

@ -0,0 +1,10 @@
program main;
int values[$];
initial begin
values = '{ 1, 3, 7, 11 };
foreach (values[i]) begin
$display( "%0d --> %0d", i, values[i] );
end
end
endprogram

View file

@ -0,0 +1,5 @@
Local i,strs
Define strs = {"Lorem","ipsum","dolor"}
For i, 1, dim(strs)
Disp strs[i]
EndFor

View file

@ -0,0 +1,5 @@
$$ MODE TUSCRIPT
week="Monday'Tuesday'Wednesday'Thursday'Friday'Saterday'Sunday"
LOOP day=week
PRINT day
ENDLOOP

View file

@ -0,0 +1 @@
[1 2 3 4 5] [print] each

View file

@ -0,0 +1,3 @@
for file in *.sh; do
echo "filename is $file"
done

View file

@ -0,0 +1,8 @@
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
oldifs=$IFS
IFS=:
for dir in $PATH; do
echo search $dir
done
IFS=$oldifs

View file

@ -0,0 +1,4 @@
collection=("first" "second" "third" "fourth" "something else")
for x in "${collection[@]}"; do
echo "$x"
done

View file

@ -0,0 +1,4 @@
set -A collection "first" "second" "third" "fourth" "something else"
for x in "${collection[@]}"; do
echo "$x"
done

View file

@ -0,0 +1,4 @@
set collection=(first second third fourth "something else")
foreach x ($collection:q)
echo $x:q
end

View file

@ -0,0 +1 @@
[1 2 3] [puts] step

View file

@ -0,0 +1,8 @@
dim items(2)
items(0)="Apple"
items(1)="Orange"
items(2)="Banana"
For Each x in items
WScript.Echo x
Next

View file

@ -0,0 +1,8 @@
Dim list As New List(Of String)
list.Add("Car")
list.Add("Boat")
list.Add("Train")
For Each item In list
Console.WriteLine(item)
Next

View file

@ -0,0 +1,6 @@
include c:\cxpl\codes;
int List, I;
[List:= ["Red", "Green", "Blue", "Black", "White"];
for I:= 0, 5-1 do
[Text(0, List(I)); CrLf(0)];
]

View file

@ -0,0 +1,4 @@
<fo:block font-weight="bold">Adults:</fo:block>
<xsl:for-each select="person[@age &gt;= 21]">
<fo:block><xsl:value-of select="position()"/>. <xsl:value-of select="@name"/></fo:block>
</xsl:for-each>