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,19 @@
using System;
using System.Console;
using Nemerle.Imperative;
module Break
{
Main() : void
{
def rnd = Random();
while (true)
{
def a = rnd.Next(20);
WriteLine(a);
when (a == 10) break;
def b = rnd.Next(20);
WriteLine(b);
}
}
}

View file

@ -0,0 +1,16 @@
/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
say
say 'Loops/Break'
rn = Rexx
rnd = Random()
loop label lb forever
rn = rnd.nextInt(19)
say rn.right(3)'\-'
if rn = 10 then leave lb
rn = rnd.nextInt(19)
say rn.right(3)'\-'
end lb
say

View file

@ -0,0 +1,18 @@
# Random.self_init();;
- : unit = ()
# while true do
let a = Random.int 20 in
print_int a;
print_newline();
if a = 10 then raise Exit;
let b = Random.int 20 in
print_int b;
print_newline()
done;;
15
18
2
13
10
Exception: Pervasives.Exit.

View file

@ -0,0 +1,9 @@
while(true) {
a := (Float->Random() * 20.0)->As(Int);
a->PrintLine();
if(a = 10) {
break;
};
a := (Float->Random() * 20.0)->As(Int);
a->PrintLine();
}

View file

@ -0,0 +1,9 @@
while(1)
a = floor(unifrnd(0,20, 1));
disp(a)
if ( a == 10 )
break
endif
b = floor(unifrnd(0,20, 1));
disp(b)
endwhile

View file

@ -0,0 +1,8 @@
for break:Break do
R = {OS.rand} mod 20
in
{Show R}
if R == 10 then {Break}
else {Show {OS.rand} mod 20}
end
end

View file

@ -0,0 +1,6 @@
while(1,
t=random(20);
print(t);
if(t==10, break);
print(random(20))
)

View file

@ -0,0 +1,7 @@
do forever;
k = random()*19;
put (k);
if k = 10 then leave;
k = random()*19;
put skip list (k);
end;

View file

@ -0,0 +1,5 @@
loop {
say my $n = (0..19).pick;
last if $n == 10;
say (0..19).pick;
}

View file

@ -0,0 +1,11 @@
int main(){
while(1){
int a = random(20);
write(a + "\n");
if(a == 10){
break;
}
int b = random(20);
write(b + "\n");
}
}

View file

@ -0,0 +1,6 @@
realtime srand % init RNG
{
rand 20 mod % generate number between 0 and 19
dup = % print it
10 eq { exit } if % exit if 10
} loop

View file

@ -0,0 +1,9 @@
$r = New-Object Random
for () {
$n = $r.Next(20)
Write-Host $n
if ($n -eq 10) {
break
}
Write-Host $r.Next(20)
}

View file

@ -0,0 +1,17 @@
If OpenConsole()
Repeat
a = Random(19)
PrintN(Str(a))
If a = 10
Break
EndIf
b = Random(19)
PrintN(Str(b))
PrintN("")
ForEver
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf

View file

@ -0,0 +1,5 @@
(define loop -> (if (= 10 (PRINT (random 20)))
true
(do (PRINT (random 20))
(loop))))
(loop)

View file

@ -0,0 +1,18 @@
REBOL [
Title: "Loop/Break"
Author: oofoe
Date: 2009-12-19
URL: http://rosettacode.org/wiki/Loop/Break
]
random/seed 1 ; Make repeatable.
; random/seed now ; Uncomment for 'true' randomness.
r20: does [(random 20) - 1]
forever [
prin x: r20
if 10 = x [break]
print rejoin [" " r20]
]
print ""

View file

@ -0,0 +1,22 @@
doc{
A couple of helper functions to make the rest of the
code more readable.
}doc
: rand ( -n ) random 20 mod ;
: . ( n- ) putn space ;
doc{
One approach is to use a simple repeat/again loop, and
a conditional exit. For instance:
}doc
: foo ( - )
repeat rand dup . 10 = if; rand . again ;
doc{
The other approach uses a structured while loop with the
second printing handled by a conditional clause.
}doc
[ rand dup . 10 <> [ [ rand . ] ifTrue ] sip ] while

View file

@ -0,0 +1,7 @@
data _null_;
do while(1);
n=floor(uniform(0)*20);
put n;
if n=10 then leave; /* 'leave' to break a loop */
end;
run;

View file

@ -0,0 +1,5 @@
input(.random,io_findunit(),1,"/dev/urandom")
while &ALPHABET random @rand
output = rand = rand - (rand / 20) * 20
eq(rand,10) :f(while)
end

View file

@ -0,0 +1,5 @@
* rand(n) -> real x | 0 <= x < n
-include 'random.sno'
loop ne(output = convert(rand(20)'integer'),10) :s(loop)
end

View file

@ -0,0 +1,7 @@
forever
{
Print(i = Random(20))
if i is 10
break
Print(i = Random(20))
}

View file

@ -0,0 +1,9 @@
Local x
Loop
rand(20)-1 → x
Disp x © new line and text
If x = 10 Then
Exit
EndIf
Output 64, 50, rand(20)-1 © paint text to the right on same line
EndLoop

View file

@ -0,0 +1,12 @@
$$ MODE TUSCRIPT
LOOP
a=RANDOM_NUMBERS (0,19,1)
IF (10==a) THEN
PRINT "a=",a
STOP
ELSE
b=RANDOM_NUMBERS (0,19,1)
PRINT "a=",a," b=",b
ENDIF
IF (10==a,b) STOP
ENDLOOP

View file

@ -0,0 +1,6 @@
for(%a = 0; %a > -1; %a++)
{
%number = getRand(0, 19);
if(%number == 10)
break;
}

View file

@ -0,0 +1,7 @@
while true; do
a=`jot -w %d -r 1 0 20` || exit $?
echo $a
test 10 -eq $a && break
b=`jot -w %d -r 1 0 20` || exit $?
echo $b
done

View file

@ -0,0 +1,5 @@
while true; do
echo $((a=RANDOM%20))
[ $a -eq 10 ] && break
echo $((b=RANDOM%20))
done

View file

@ -0,0 +1,16 @@
do
a = int( rnd * 20)
wscript.stdout.write a
if a = 10 then exit do
b = int( rnd * 20 )
wscript.echo vbnullstring,b
loop
dim i
for i = 1 to 100000
a = int( rnd * 20)
wscript.stdout.write a
if a = 10 then exit for
b = int( rnd * 20 )
wscript.echo vbnullstring,b
next

View file

@ -0,0 +1,9 @@
include c:\cxpl\codes;
int N;
loop [N:= Ran(20);
IntOut(0, N);
if N=10 then quit;
ChOut(0, 9\tab\);
IntOut(0, Ran(20));
CrLf(0);
]