Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
---
category:
- Loop modifiers
- Simple
from: http://rosettacode.org/wiki/Loops/Break
note: Iteration

View file

@ -0,0 +1,27 @@
;Task:
Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive).
If a number is 10, stop the loop after printing it, and do not generate any further numbers.
Otherwise, generate and print a second random number before restarting the loop.
If the number 10 is never generated as the first number in a loop, loop forever.
;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]]
*   [[Loops/with multiple ranges]]
<br><br>

View file

@ -0,0 +1,7 @@
L
V a = random:(20)
print(a)
I a == 10
L.break
V b = random:(20)
print(b)

View file

@ -0,0 +1,39 @@
* Loops Break 15/02/2017
LOOPBREA CSECT
USING LOOPBREA,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) prolog
ST R13,4(R15) " <-
ST R15,8(R13) " ->
LR R13,R15 " addressability
LOOP MVC PG,=CL80' ' clean buffer
LA R8,PG ipg=0
BAL R14,RANDINT call randint
C R6,=F'10' if k=10 then leave
BE ENDLOOP <-- loop break
BAL R14,RANDINT call randint
XPRNT PG,L'PG print buffer
B LOOP loop forever
ENDLOOP XPRNT PG,L'PG print buffer
L R13,4(0,R13) epilog
LM R14,R12,12(R13) " restore
XR R15,R15 " rc=0
BR R14 exit
RANDINT L R5,RANDSEED randint
M R4,=F'397204091' "
D R4,=X'7FFFFFFF' "
ST R4,RANDSEED "
LR R5,R4 "
SR R4,R4 "
D R4,=F'20' "
LR R6,R4 k=randint(20)
XDECO R6,XDEC edit k
MVC 0(4,R8),XDEC+8 output k
LA R8,4(R8) ipg=ipg+4
BR R14 return
RANDSEED DC F'39710831' seed
PG DS CL80 buffer
XDEC DS CL12
YREGS
END LOOPBREA

View file

@ -0,0 +1,17 @@
LoopBreakSub: PHA ;push accumulator onto stack
BreakLoop: JSR GenerateRandomNum ;routine not implemented
;generates random number and puts in memory location RandomNumber
LDA RandomNumber
JSR DisplayAccumulator ;routine not implemented
CMP #10
BEQ Break
JSR GenerateRandomNum
LDA RandomNumber
JSR DisplayAccumulator
JMP BreakLoop
Break: PLA ;restore accumulator from stack
RTS ;return from subroutine

View file

@ -0,0 +1,96 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program loopbreak64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessEndLoop: .asciz "loop break with value : \n"
szMessResult: .asciz "Resultat = @ \n" // message result
.align 4
qGraine: .quad 12345678
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
1: // begin loop
mov x4,20
2:
mov x0,19
bl genereraleas // generate number
cmp x0,10 // compar value
beq 3f // break if equal
ldr x1,qAdrsZoneConv // display value
bl conversion10 // call function with 2 parameter (x0,x1)
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at third @ character
bl affichageMess // display message final
subs x4,x4,1 // decrement counter
bgt 2b // loop if greather
b 1b // begin loop one
3:
mov x2,x0 // save value
ldr x0,qAdrszMessEndLoop
bl affichageMess // display message
mov x0,x2
ldr x1,qAdrsZoneConv
bl conversion10 // call function with 2 parameter (x0,x1)
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at third @ character
bl affichageMess // display message
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrsZoneConv: .quad sZoneConv
qAdrszMessResult: .quad szMessResult
qAdrszMessEndLoop: .quad szMessEndLoop
/***************************************************/
/* Generation random number */
/***************************************************/
/* x0 contains limit */
genereraleas:
stp x1,lr,[sp,-16]! // save registers
stp x2,x3,[sp,-16]! // save registers
ldr x3,qAdrqGraine // load graine
ldr x2,[x3]
lsr x1,x2,17 // see xorshift on wikipedia
eor x2,x2,x1
lsl x1,x2,31
eor x2,x2,x1
lsr x1,x2,8
eor x1,x2,x1
str x1,[x3] // save graine for the next call
udiv x1,x2,x0 // divide by value maxi
msub x0,x1,x0,x2 // résult = remainder
100: // end function
ldp x2,x3,[sp],16 // restaur 2 registers
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/********************************************************************/
qAdrqGraine: .quad qGraine
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,25 @@
'BEGIN' 'COMMENT' Loops/Break - ALGOL60 - 18/06/2018;
'INTEGER' SEED;
'INTEGER' 'PROCEDURE' RANDOM(N);
'VALUE' N; 'INTEGER' N;
'BEGIN'
SEED:=(SEED*19157+12347) '/' 21647;
RANDOM:=SEED-(SEED '/' N)*N+1
'END' RANDOM;
'INTEGER' I,J,K;
SYSACT(1,6,120);SYSACT(1,8,60);SYSACT(1,12,1);'COMMENT' open print;
SEED:=31567;
J:=0;
'FOR' I:=1, I+1 'WHILE' I 'LESS' 100 'DO' 'BEGIN'
J:=J+1;
K:=RANDOM(20);
OUTINTEGER(1,K);
'IF' J=8 'THEN' 'BEGIN'
SYSACT(1,14,1); 'COMMENT' skip line;
J:=0
'END';
'IF' K=10 'THEN' 'GOTO' LAB
'END';
LAB:
SYSACT(1,14,1); 'COMMENT' skip line;
'END'

View file

@ -0,0 +1,13 @@
main: (
INT a, b;
INT seed := 4; # chosen by a fair dice roll, guaranteed to be random c.f. http://xkcd.com/221/ #
# first random; #
WHILE
a := ENTIER (next random(seed) * 20);
print((a));
# WHILE # NOT (a = 10) DO
b := ENTIER (next random(seed) * 20);
print((b, new line))
OD;
print(new line)
)

View file

@ -0,0 +1,181 @@
/* ARM assembly Raspberry PI */
/* program loopbreak.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessEndLoop: .asciz "loop break with value : \n"
szMessResult: .ascii "Resultat = " @ message result
sMessValeur: .fill 12, 1, ' '
.asciz "\n"
.align 4
iGraine: .int 123456
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
push {fp,lr} @ saves 2 registers
1: @ begin loop
mov r4,#20
2:
mov r0,#19
bl genereraleas @ generate number
cmp r0,#10 @ compar value
beq 3f @ break if equal
ldr r1,iAdrsMessValeur @ display value
bl conversion10 @ call function with 2 parameter (r0,r1)
ldr r0,iAdrszMessResult
bl affichageMess @ display message
subs r4,#1 @ decrement counter
bgt 2b @ loop if greather
b 1b @ begin loop one
3:
mov r2,r0 @ save value
ldr r0,iAdrszMessEndLoop
bl affichageMess @ display message
mov r0,r2
ldr r1,iAdrsMessValeur
bl conversion10 @ call function with 2 parameter (r0,r1)
ldr r0,iAdrszMessResult
bl affichageMess @ display message
100: @ standard end of the program
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrsMessValeur: .int sMessValeur
iAdrszMessResult: .int szMessResult
iAdrszMessEndLoop: .int szMessEndLoop
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registres
mov r2,#0 @ counter length
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call systeme
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
bx lr @ return
/******************************************************************/
/* Converting a register to a decimal */
/******************************************************************/
/* r0 contains value and r1 address area */
conversion10:
push {r1-r4,lr} @ save registers
mov r3,r1
mov r2,#10
1: @ start loop
bl divisionpar10 @ r0 <- dividende. quotient ->r0 reste -> r1
add r1,#48 @ digit
strb r1,[r3,r2] @ store digit on area
sub r2,#1 @ previous position
cmp r0,#0 @ stop if quotient = 0 */
bne 1b @ else loop
@ and move spaces in first on area
mov r1,#' ' @ space
2:
strb r1,[r3,r2] @ store space in area
subs r2,#1 @ @ previous position
bge 2b @ loop if r2 >= zéro
100:
pop {r1-r4,lr} @ restaur registres
bx lr @return
/***************************************************/
/* division par 10 signé */
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
/* and http://www.hackersdelight.org/ */
/***************************************************/
/* r0 dividende */
/* r0 quotient */
/* r1 remainder */
divisionpar10:
/* r0 contains the argument to be divided by 10 */
push {r2-r4} /* save registers */
mov r4,r0
mov r3,#0x6667 @ r3 <- magic_number lower
movt r3,#0x6666 @ r3 <- magic_number upper
smull r1, r2, r3, r0 @ r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0)
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
add r0, r2, r1 /* r0 <- r2 + r1 */
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
pop {r2-r4}
bx lr /* leave function */
/***************************************************/
/* Generation random number */
/***************************************************/
/* r0 contains limit */
genereraleas:
push {r1-r4,lr} @ save registers
ldr r4,iAdriGraine
ldr r2,[r4]
ldr r3,iNbDep1
mul r2,r3,r2
ldr r3,iNbDep1
add r2,r2,r3
str r2,[r4] @ maj de la graine pour l appel suivant
mov r1,r0 @ divisor
mov r0,r2 @ dividende
bl division
mov r0,r3 @ résult = remainder
100: @ end function
pop {r1-r4,lr} @ restaur registers
bx lr @ return
/********************************************************************/
iAdriGraine: .int iGraine
iNbDep1: .int 0x343FD
iNbDep2: .int 0x269EC3
/***************************************************/
/* integer division unsigned */
/***************************************************/
division:
/* r0 contains dividend */
/* r1 contains divisor */
/* r2 returns quotient */
/* r3 returns remainder */
push {r4, lr}
mov r2, #0 @ init quotient
mov r3, #0 @ init remainder
mov r4, #32 @ init counter bits
b 2f
1: @ loop
movs r0, r0, LSL #1 @ r0 <- r0 << 1 updating cpsr (sets C if 31st bit of r0 was 1)
adc r3, r3, r3 @ r3 <- r3 + r3 + C. This is equivalent to r3 <- (r3 << 1) + C
cmp r3, r1 @ compute r3 - r1 and update cpsr
subhs r3, r3, r1 @ if r3 >= r1 (C=1) then r3 <- r3 - r1
adc r2, r2, r2 @ r2 <- r2 + r2 + C. This is equivalent to r2 <- (r2 << 1) + C
2:
subs r4, r4, #1 @ r4 <- r4 - 1
bpl 1b @ if r4 >= 0 (N=0) then loop
pop {r4, lr}
bx lr

View file

@ -0,0 +1,9 @@
BEGIN {
srand() # randomize the RNG
for (;;) {
print n = int(rand() * 20)
if (n == 10)
break
print int(rand() * 20)
}
}

View file

@ -0,0 +1,13 @@
PROC Main()
BYTE v
PrintE("Before loop")
DO
v=Rand(20)
PrintBE(v)
IF v=10 THEN
EXIT
FI
OD
PrintE("After loop")
RETURN

View file

@ -0,0 +1,18 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
procedure Test_Loop_Break is
type Value_Type is range 0..19;
package Random_Values is new Ada.Numerics.Discrete_Random (Value_Type);
use Random_Values;
Dice : Generator;
A, B : Value_Type;
begin
loop
A := Random (Dice);
Put_Line (Value_Type'Image (A));
exit when A = 10;
B := Random (Dice);
Put_Line (Value_Type'Image (B));
end loop;
end Test_Loop_Break;

View file

@ -0,0 +1,20 @@
integer
main(void)
{
integer a, b;
while (1) {
a = drand(19);
o_integer(a);
o_byte('\n');
if (a == 10) {
break;
}
b = drand(19);
o_integer(b);
o_byte('\n');
}
return 0;
}

View file

@ -0,0 +1,9 @@
repeat
set a to random number from 0 to 19
if a is 10 then
log a
exit repeat
end if
set b to random number from 0 to 19
log a & b
end repeat

View file

@ -0,0 +1 @@
FOR I = 0 TO 1 STEP 0 : N = INT(RND(1) * 20) : PRINT " "N; : IF N <> 10 THEN ? ","INT(RND(1) * 20); : NEXT

View file

@ -0,0 +1,7 @@
(point break
(while t
(let x (rand 20)
(prn "a: " x)
(if (is x 10)
(break)))
(prn "b: " (rand 20))))

View file

@ -0,0 +1,9 @@
while ø [
a: random 0 19
prints [a ""]
if a=10 -> break
b: random 0 19
print b
]
print ""

View file

@ -0,0 +1,10 @@
Loop
{
Random, var, 0, 19
output = %output%`n%var%
If (var = 10)
Break
Random, var, 0, 19
output = %output%`n%var%
}
MsgBox % output

View file

@ -0,0 +1,8 @@
rng ::= a pRNG;
checked : [0..19];
Do [
checked : = rng's next [0..19];
Print: “checked”;
] while checked ≠ 10 alternate with [
Print: " " ++ “rng's next [0..19]” ++ "\n";
];

View file

@ -0,0 +1,7 @@
While 1
rand^20→A
Disp A▶Dec
ReturnIf A=10
rand^20→B
Disp B▶Dec,i
End

View file

@ -0,0 +1,9 @@
do
i = int(rand * 19)
print i; " ";
if i = 10 then exit do
i = int(rand * 19)
print i; " ";
until false
print
end

View file

@ -0,0 +1,6 @@
REPEAT
num% = RND(20)-1
PRINT num%
IF num%=10 THEN EXIT REPEAT
PRINT RND(20)-1
UNTIL FALSE

View file

@ -0,0 +1,8 @@
REPEAT
number = RANDOM(20)
PRINT "first " ,number
IF number = 10 THEN
BREAK
ENDIF
PRINT "second ",RANDOM(20)
UNTIL FALSE

View file

@ -0,0 +1,8 @@
@echo off
:loop
set /a N=%RANDOM% %% 20
echo %N%
if %N%==10 exit /b
set /a N=%RANDOM% %% 20
echo %N%
goto loop

View file

@ -0,0 +1,23 @@
s = 1 /* seed of the random number generator */
scale = 0
/* Random number from 0 to 20. */
define r() {
auto a
while (1) {
/* Formula (from POSIX) for random numbers of low quality. */
s = (s * 1103515245 + 12345) % 4294967296
a = s / 65536 /* a in [0, 65536) */
if (a >= 16) break /* want a >= 65536 % 20 */
}
return (a % 20)
}
while (1) {
n = r()
n /* print 1st number */
if (n == 10) break
r() /* print 2nd number */
}
quit

View file

@ -0,0 +1,11 @@
>60v *2\<
>?>\1-:|
1+ $
>^ 7
v.:%++67<
>55+-#v_@
>60v *2\<
>?>\1-:|
1+ $
>^ 7
^ .%++67<

View file

@ -0,0 +1,16 @@
#include <iostream>
#include <ctime>
#include <cstdlib>
int main(){
srand(time(NULL)); // randomize seed
while(true){
const int a = rand() % 20; // biased towards lower numbers if RANDMAX % 20 > 0
std::cout << a << std::endl;
if(a == 10)
break;
const int b = rand() % 20;
std::cout << b << std::endl;
}
return 0;
}

View file

@ -0,0 +1,18 @@
class Program
{
static void Main(string[] args)
{
Random random = new Random();
while (true)
{
int a = random.Next(20);
Console.WriteLine(a);
if (a == 10)
break;
int b = random.Next(20)
Console.WriteLine(b);
}
Console.ReadLine();
}
}

View file

@ -0,0 +1,14 @@
int main(){
time_t t;
int a, b;
srand((unsigned)time(&t));
for(;;){
a = rand() % 20;
printf("%d\n", a);
if(a == 10)
break;
b = rand() % 20;
printf("%d\n", b);
}
return 0;
}

View file

@ -0,0 +1,26 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Random-Nums.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num PIC Z9.
PROCEDURE DIVISION.
Main.
PERFORM FOREVER
PERFORM Generate-And-Display-Num
IF Num = 10
EXIT PERFORM
ELSE
PERFORM Generate-And-Display-Num
END-IF
END-PERFORM
GOBACK
.
Generate-And-Display-Num.
COMPUTE Num = FUNCTION REM(FUNCTION RANDOM * 100, 20)
DISPLAY Num
.

View file

@ -0,0 +1,11 @@
use Random;
var r = new RandomStream();
while true {
var a = floor(r.getNext() * 20):int;
writeln(a);
if a == 10 then break;
var b = floor(r.getNext() * 20):int;
writeln(b);
}
delete r;

View file

@ -0,0 +1,58 @@
Healthy Vita-Sauce Loop - Broken.
Makes a whole lot of sauce for two people.
Ingredients.
0 g Vitamin A
1 g Vitamin B
2 g Vitamin C
3 g Vitamin D
4 g Vitamin E
5 g Vitamin F
6 g Vitamin G
7 g Vitamin H
8 g Vitamin I
9 g Vitamin J
10 g Vitamin K
11 g Vitamin L
12 g Vitamin M
13 g Vitamin N
14 g Vitamin O
15 g Vitamin P
16 g Vitamin Q
17 g Vitamin R
18 g Vitamin S
19 g Vitamin T
20 g Vitamin U
21 g Vitamin V
22 g Vitamin W
32 g Vitamin X
24 g Vitamin Y
25 g Vitamin Z
Method.
Liquify Vitamin X.
Put Vitamin N into 1st mixing bowl.
Fold Vitamin Y into 1st mixing bowl.
Liquify Vitamin Y.
Clean 1st mixing bowl.
Put Vitamin K into 1st mixing bowl.
Fold Vitamin Z into 1st mixing bowl.
Liquify Vitamin Z.
Clean 1st mixing bowl.
Put Vitamin Y into 4th mixing bowl.
Put Vitamin Z into 4th mixing bowl.
Pour contents of the 4th mixing bowl into the 2nd baking dish.
Put Vitamin A into 2nd mixing bowl. Put Vitamin B into 2nd mixing bowl. Put Vitamin C into 2nd mixing bowl. Put Vitamin D into 2nd mixing bowl. Put Vitamin E into 2nd mixing bowl. Put Vitamin F into 2nd mixing bowl. Put Vitamin G into 2nd mixing bowl. Put Vitamin H into 2nd mixing bowl. Put Vitamin I into 2nd mixing bowl. Put Vitamin J into 2nd mixing bowl. Put Vitamin K into 2nd mixing bowl. Put Vitamin L into 2nd mixing bowl. Put Vitamin M into 2nd mixing bowl. Put Vitamin N into 2nd mixing bowl. Put Vitamin O into 2nd mixing bowl. Put Vitamin P into 2nd mixing bowl. Put Vitamin Q into 2nd mixing bowl. Put Vitamin R into 2nd mixing bowl. Put Vitamin S into 2nd mixing bowl. Put Vitamin T into 2nd mixing bowl.
Verb the Vitamin V.
Mix the 2nd mixing bowl well.
Fold Vitamin U into 2nd mixing bowl.
Put Vitamin U into 3rd mixing bowl.
Remove Vitamin K from 3rd mixing bowl.
Fold Vitamin V into 3rd mixing bowl.
Put Vitamin X into 1st mixing bowl.
Put Vitamin V into 1st mixing bowl.
Verb until verbed.
Pour contents of the 1st mixing bowl into the 1st baking dish.
Serves 2.

View file

@ -0,0 +1,5 @@
(loop [[a b & more] (repeatedly #(rand-int 20))]
(println a)
(when-not (= 10 a)
(println b)
(recur more)))

View file

@ -0,0 +1,4 @@
loop
print a = Math.random() * 20 // 1
break if a == 10
print Math.random() * 20 // 1

View file

@ -0,0 +1,8 @@
<Cfset randNum = 0>
<cfloop condition="randNum neq 10">
<Cfset randNum = RandRange(0, 19)>
<Cfoutput>#randNum#</Cfoutput>
<Cfif randNum eq 10><cfbreak></Cfif>
<Cfoutput>#RandRange(0, 19)#</Cfoutput>
<Br>
</cfloop>

View file

@ -0,0 +1,8 @@
10 X = RND(-TI) : REM SEED RN GENERATOR
20 A = INT(RND(1)*20)
30 PRINT A
40 IF A = 10 THEN 80
50 B = INT(RND(1)*20)
60 PRINT B
70 GOTO 20
80 END

View file

@ -0,0 +1,4 @@
(loop for a = (random 20)
do (print a)
until (= a 10)
do (print (random 20)))

View file

@ -0,0 +1,3 @@
(do ((a (random 20) (random 20))) ; Initialize to rand and set new rand on every loop
((= a 10) (write a)) ; Break condition and last step
(format t "~a~3T~a~%" a (random 20))) ; On every loop print formated `a' and rand `b'

View file

@ -0,0 +1,11 @@
import std.stdio, std.random;
void main() {
while (true) {
int r = uniform(0, 20);
write(r, " ");
if (r == 10)
break;
write(uniform(0, 20), " ");
}
}

View file

@ -0,0 +1,5 @@
while True do begin
var num := RandomInt(20);
PrintLn(num);
if num=10 then Break;
end;

View file

@ -0,0 +1,25 @@
1 ss [s = seed of the random number generator]sz
0k [scale = 0]sz
[Function r: Push a random number from 0 to 20.]sz
[
[2Q]SA
[
[Formula (from POSIX) for random numbers of low quality.]sz
ls 1103515245 * 12345 + 4294967296 % d ss [Compute next s]sz
65536 / [it = s / 65536]sz
d 16 !>A [Break loop if 16 <= it]sz
sz 0 0 =B [Forget it, continue loop]sz
]SB 0 0 =B
20 % [Push it % 20]sz
LA sz LB sz [Restore A, B]sz
]sr
[2Q]sA
[
0 0 =r p [Print 1st number.]sz
10 =A [Break if 10 == it.]sz
0 0 =r p sz [Print 2nd number.]sz
0 0 =B [Continue loop.]sz
]sB 0 0 =B

View file

@ -0,0 +1,15 @@
program Project5;
{$APPTYPE CONSOLE}
var
num:Integer;
begin
Randomize;
while true do
begin
num:=Random(20);
Writeln(num);
if num=10 then break;
end;
end.

View file

@ -0,0 +1,9 @@
while (true) {
def a := entropy.nextInt(20)
print(a)
if (a == 10) {
println()
break
}
println(" ", entropy.nextInt(20))
}

View file

@ -0,0 +1,7 @@
for ever
int a = random(20)
write(a)
if a == 10 do break end
writeLine("," + random(20))
end
writeLine()

View file

@ -0,0 +1,6 @@
LOOP
A=INT(RND(1)*20)
PRINT(A)
IF A=10 THEN EXIT LOOP END IF !EXIT FOR works the same inside FOR loops
PRINT(INT(RND(1)*20))
END LOOP

View file

@ -0,0 +1,6 @@
repeat
a = random 20
print a
until a = 10
print random 20
.

View file

@ -0,0 +1,15 @@
example
-- Eiffel example code
local
n: INTEGER
r: RANDOMIZER
do
from
create r
n := r.random_integer_in_range (0 |..| 19)
until
n = 10
loop
n := r.random_integer_in_range (0 |..| 19)
end
end

View file

@ -0,0 +1,12 @@
open datetime random monad io
loop = loop' 1
where loop' n t = do
dt <- datetime.now
seed <- return <| toInt <| (ticks <| dt) * n
r <- return $ rnd seed 0 19
putStrLn (show r)
if r <> t then loop' (n + 1) t else return ()
loop 10 ::: IO

View file

@ -0,0 +1,13 @@
defmodule Loops do
def break, do: break(random)
defp break(10), do: IO.puts 10
defp break(r) do
IO.puts "#{r},\t#{random}"
break(random)
end
defp random, do: Enum.random(0..19)
end
Loops.break

View file

@ -0,0 +1,10 @@
(defun wait_10 ()
(catch 'loop-break
(while 't
(let ((math (random 19)))
(if (= math 10)
(progn (message "Found value: %d" math)
(throw 'loop-break math))
(message "current number is: %d" math) ) ) ) ) )
(wait_10)

View file

@ -0,0 +1,17 @@
%% Implemented by Arjun Sunel
-module(forever).
-export([main/0, for/0]).
main() ->
for().
for() ->
K = random:uniform(19),
io:fwrite( "~p ", [K] ),
if K==10 ->
ok;
true ->
M = random:uniform(19),
io:format("~p~n",[M]),
for()
end.

View file

@ -0,0 +1,9 @@
integer i
while 1 do
i = rand(20) - 1
printf(1, "%g ", {i})
if i = 10 then
exit
end if
printf(1, "%g ", {rand(20)-1})
end while

View file

@ -0,0 +1,4 @@
// Loops/Break. Nigel Galloway: February 21st., 2022
let n=System.Random()
let rec fN g=printf "%d " g; if g <> 10 then fN(n.Next(20))
fN(n.Next(20))

View file

@ -0,0 +1,3 @@
[
[ 20 random [ . ] [ 10 = [ return ] when ] bi 20 random . t ] loop
] with-return

View file

@ -0,0 +1 @@
[ 20 random [ . ] [ 10 = not ] bi dup [ 20 random . ] when ] loop

View file

@ -0,0 +1,13 @@
class ForBreak
{
public static Void main ()
{
while (true)
{
a := Int.random(0..19)
echo (a)
if (a == 10) break
echo (Int.random(0..19))
}
}
}

View file

@ -0,0 +1,14 @@
include random.fs
: main
begin 20 random dup . 10 <>
while 20 random .
repeat ;
\ use LEAVE to break out of a counted loop
: main
100 0 do
i random dup .
10 = if leave then
i random .
loop ;

View file

@ -0,0 +1,17 @@
program Example
implicit none
real :: r
integer :: a, b
do
call random_number(r)
a = int(r * 20)
write(*,*) a
if (a == 10) exit
call random_number(r)
b = int(r * 20)
write(*,*) b
end do
end program Example

View file

@ -0,0 +1,69 @@
PROGRAM LOOPBREAK
INTEGER I, RNDINT
C It doesn't matter what number you put here.
CALL SDRAND(123)
C Because FORTRAN 77 semantically lacks many loop structures, we
C have to use GOTO statements to do the same thing.
10 CONTINUE
C Print a random number.
I = RNDINT(0, 19)
WRITE (*,*) I
C If the random number is ten, break (i.e. skip to after the end
C of the "loop").
IF (I .EQ. 10) GOTO 20
C Otherwise, print a second random number.
I = RNDINT(0, 19)
WRITE (*,*) I
C This is the end of our "loop," meaning we jump back to the
C beginning again.
GOTO 10
20 CONTINUE
STOP
END
C FORTRAN 77 does not come with a random number generator, but it
C is easy enough to type "fortran 77 random number generator" into your
C preferred search engine and to copy and paste what you find. The
C following code is a slightly-modified version of:
C
C http://www.tat.physik.uni-tuebingen.de/
C ~kley/lehre/ftn77/tutorial/subprograms.html
SUBROUTINE SDRAND (IRSEED)
COMMON /SEED/ UTSEED, IRFRST
UTSEED = IRSEED
IRFRST = 0
RETURN
END
INTEGER FUNCTION RNDINT (IFROM, ITO)
INTEGER IFROM, ITO
PARAMETER (MPLIER=16807, MODLUS=2147483647, &
& MOBYMP=127773, MOMDMP=2836)
COMMON /SEED/ UTSEED, IRFRST
INTEGER HVLUE, LVLUE, TESTV, NEXTN
SAVE NEXTN
IF (IRFRST .EQ. 0) THEN
NEXTN = UTSEED
IRFRST = 1
ENDIF
HVLUE = NEXTN / MOBYMP
LVLUE = MOD(NEXTN, MOBYMP)
TESTV = MPLIER*LVLUE - MOMDMP*HVLUE
IF (TESTV .GT. 0) THEN
NEXTN = TESTV
ELSE
NEXTN = TESTV + MODLUS
ENDIF
IF (NEXTN .GE. 0) THEN
RNDINT = MOD(MOD(NEXTN, MODLUS), ITO - IFROM + 1) + IFROM
ELSE
RNDINT = MOD(MOD(NEXTN, MODLUS), ITO - IFROM + 1) + ITO + 1
ENDIF
RETURN
END

View file

@ -0,0 +1,31 @@
SUBROUTINE RANDU(IX,IY,YFL)
Copied from the IBM1130 Scientific Subroutines Package (1130-CM-02X): Programmer's Manual, page 60.
CAUTION! This routine's 32-bit variant is reviled by Prof. Knuth and many others for good reason!
IY = IX*899
IF (IY) 5,6,6
5 IY = IY + 32767 + 1
6 YFL = IY
YFL = YFL/32767.
END
FUNCTION IR19(IX)
CALL RANDU(IX,IY,YFL)
IX = IY
I = YFL*20
IF (I - 20) 12,11,11
11 I = 19
12 IR19 = I
END
IX = 1
Commence the loop.
10 I = IR19(IX)
WRITE (6,11) I
11 FORMAT (I3)
IF (I - 10) 12,20,12
12 I = IR19(IX)
WRITE (6,11) I
GO TO 10
Cease.
20 CONTINUE
END

View file

@ -0,0 +1,16 @@
' FB 1.05.0 Win64
Dim i As Integer
Randomize
Do
i = Int(Rnd * 20)
Print Using "##"; i;
Print " ";
If i = 10 Then Exit Do
i = Int(Rnd * 20)
Print Using "##"; i;
Print" ";
Loop
Print
Sleep

View file

@ -0,0 +1,10 @@
while true
{
a = random[0,19]
print["$a "]
if a == 10
break
b = random[0,19]
print["$b "]
}

View file

@ -0,0 +1,9 @@
include "NSLog.incl"
long num
do
num = rnd(20) - 1
NSLog(@"%ld",num)
until ( num == 10 )
HandleEvents

View file

@ -0,0 +1,17 @@
while true do
a := Random(0, 19);
Print(a);
if a = 10 then
Print("\n");
break;
fi;
a := Random(0, 19);
Print("\t", a, "\n");
od;
# 11 6
# 5 8
# 1 4
# 5 10
# 1 16
# 10

View file

@ -0,0 +1,15 @@
extends MainLoop
func _process(_delta: float) -> bool:
randomize()
while true:
var a: int = randi_range(0, 19)
print(a)
if a == 10:
break
var b: int = randi_range(0, 19)
print(b)
return true # Exit

View file

@ -0,0 +1,9 @@
while(1)
{
a = floor(random(19))
show_message(string(a))
if(a = 10)
break
b = floor(random(19))
show_message(string(a))
}

View file

@ -0,0 +1,5 @@
10 NUM = 0
20 WHILE NUM <> 10
30 NUM = INT(RND * 20)
40 PRINT NUM
50 WEND

View file

@ -0,0 +1,9 @@
Public Sub Form_Open()
Dim iRand As Integer
Repeat
iRand = Rnd * 20
Print iRand
Until iRand = 10
End

View file

@ -0,0 +1,12 @@
Public Sub Main()
Dim byNo As Byte
Do
byNo = Rand(0, 19)
Print byNo;;
If byNo = 10 Then Break
byNo = Rand(0, 19)
Print byNo;;
Loop
End

View file

@ -0,0 +1,18 @@
package main
import "fmt"
import "math/rand"
import "time"
func main() {
rand.Seed(time.Now().UnixNano())
for {
a := rand.Intn(20)
fmt.Println(a)
if a == 10 {
break
}
b := rand.Intn(20)
fmt.Println(b)
}
}

View file

@ -0,0 +1,9 @@
final random = new Random()
while (true) {
def random1 = random.nextInt(20)
print random1
if (random1 == 10) break
print ' '
println random.nextInt(20)
}

View file

@ -0,0 +1,13 @@
PROCEDURE Loop()
LOCAL n
DO WHILE .T.
? n := hb_RandomInt( 0, 19 )
IF n == 10
EXIT
ENDIF
? hb_RandomInt( 0, 19 )
ENDDO
RETURN

View file

@ -0,0 +1,9 @@
import Control.Monad
import System.Random
loopBreak n k = do
r <- randomRIO (0,n)
print r
unless (r==k) $ do
print =<< randomRIO (0,n)
loopBreak n k

View file

@ -0,0 +1 @@
loopBreak 19 10

View file

@ -0,0 +1,12 @@
class Program {
static public function main():Void {
while(true) {
var a = Std.random(20);
Sys.println(a);
if (a == 10)
break;
var b = Std.random(20);
Sys.println(b);
}
}
}

View file

@ -0,0 +1,8 @@
while true
let r rand 20
println r
if r = 10
break
endif
println rand 20
endwhile

View file

@ -0,0 +1,9 @@
1 DO i = 1, 1E20 ! "forever"
a = INT( RAN(10, 10) )
WRITE(name) a
IF( a == 10) GOTO 10
b = INT( RAN(10, 10) )
WRITE(name) b
ENDDO
10
END

View file

@ -0,0 +1,10 @@
U16 a, b;
while (1) {
a = RandU16 % 20;
Print("%d\n", a);
if (a == 10) break;
b = RandU16 % 20;
Print("%d\n", b);
}

View file

@ -0,0 +1,7 @@
100 RANDOMIZE
110 DO
120 LET A=RND(20)+1
130 PRINT A,
140 IF A=10 THEN EXIT DO
150 PRINT RND(20)+1
160 LOOP

View file

@ -0,0 +1,3 @@
procedure main()
while 10 ~= writes(?20-1) do write(", ",?20-1)
end

View file

@ -0,0 +1 @@
&random := integer(map("smhSMH","Hh:Mm:Ss",&clock))

View file

@ -0,0 +1,7 @@
loop(
a := Random value(0,20) floor
write(a)
if( a == 10, writeln ; break)
b := Random value(0,20) floor
writeln(" ",b)
)

View file

@ -0,0 +1,20 @@
]F.(( _2 Z: 10&= [ echo)@(?@20))''
15
6
5
10
]F.(( _2 Z: 10&= [ echo)@(?@20))''
14
9
3
8
19
14
5
13
8
1
19
2
10

View file

@ -0,0 +1,7 @@
loopexample=: {{
while. do.
echo k=. ?20
if. 10=k do. return. end.
echo ?20
end.
}}

View file

@ -0,0 +1,7 @@
loopexample2=: verb define
while. do.
echo k=. ?20
if. 10=k do. break. end.
echo ?20
end.
)

View file

@ -0,0 +1,8 @@
loopexample3=: {{
while. do.
echo k=. ?20
if. 10=k do. goto_done. end.
echo ?20
end.
label_done.
}}

View file

@ -0,0 +1,22 @@
fn random(mut random_source: File = File::open_for_reading("/dev/urandom")) throws -> u64 {
mut buffer = [0u8; 4]
random_source.read(buffer)
mut result = 0u64
for byte in buffer {
result <<= 8
result += byte as! u64
}
return result
}
fn main() {
while true {
let n = random() % 20
println("{}", n)
if n == 10 {
break
}
println("{}", random() % 20)
}
}

View file

@ -0,0 +1,10 @@
import java.util.Random;
Random rand = new Random();
while(true){
int a = rand.nextInt(20);
System.out.println(a);
if(a == 10) break;
int b = rand.nextInt(20);
System.out.println(b);
}

View file

@ -0,0 +1,8 @@
for (;;) {
var a = Math.floor(Math.random() * 20);
print(a);
if (a == 10)
break;
a = Math.floor(Math.random() * 20);
print(a);
}

View file

@ -0,0 +1,13 @@
(function streamTillInitialTen() {
var nFirst = Math.floor(Math.random() * 20);
console.log(nFirst);
if (nFirst === 10) return true;
console.log(
Math.floor(Math.random() * 20)
);
return streamTillInitialTen();
})();

View file

@ -0,0 +1,14 @@
console.log(
(function streamTillInitialTen() {
var nFirst = Math.floor(Math.random() * 20);
if (nFirst === 10) return [10];
return [
nFirst,
Math.floor(Math.random() * 20)
].concat(
streamTillInitialTen()
);
})().join('\n')
);

View file

@ -0,0 +1,16 @@
# 15-bit integers generated using the same formula as rand()
# from the Microsoft C Runtime.
# Input: [ count, state, rand ]
def next_rand_Microsoft:
.[0] as $count | .[1] as $state
| ( (214013 * $state) + 2531011) % 2147483648 # mod 2^31
| [$count+1 , ., (. / 65536 | floor) ];
def rand_Microsoft(seed):
[0,seed]
| next_rand_Microsoft # the seed is not so random
| recurse( next_rand_Microsoft )
| .[2];
# Generate random integers from 0 to (n-1):
def rand(n): n * (rand_Microsoft(17) / 32768) | trunc;

View file

@ -0,0 +1,3 @@
def take(s; cond):
label $done
| foreach s as $n (null; $n; if $n | cond | not then break $done else . end);

View file

@ -0,0 +1 @@
def count(s): reduce s as $i (0; . + 1);

View file

@ -0,0 +1,10 @@
while true
n = rand(0:19)
@printf "%4d" n
if n == 10
println()
break
end
n = rand(0:19)
@printf "%4d\n" n
end

View file

@ -0,0 +1,10 @@
import kotlin.random.Random
fun main() {
while (true) {
val a = Random.nextInt(20)
println(a)
if (a == 10) break
println(Random.nextInt(20))
}
}

View file

@ -0,0 +1,9 @@
{def loops_break
{lambda {:n}
{if {= :n 10}
then :n -> end of loop
else :n {loops_break {round {* 20 {random}}}}}}}
-> loops_break
{loops_break 0}
-> 0 16 8 5 9 17 9 18 1 18 1 1 12 13 15 1 10 -> end of loop

View file

@ -0,0 +1,13 @@
loop {
$a = fn.randRange(20)
fn.printf(%2d, $a)
if($a === 10) {
fn.println()
con.break
}
$b = fn.randRange(20)
fn.printf(\s- %2d%n, $b)
}

View file

@ -0,0 +1 @@
do 20 ? int dup . 10 == if break then 20 ? int . loop

View file

@ -0,0 +1,6 @@
for {
val .i = random 0..19
write .i, " "
if .i == 10 { writeln(); break }
write random(0..19), " "
}

Some files were not shown because too many files have changed in this diff Show more