September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,4 +1,9 @@
|
|||
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.
|
||||
;Task:
|
||||
Show a loop which prints random numbers (each number newly generated each loop) from '''0''' to '''19''' (inclusive).
|
||||
|
||||
If a number is '''0''' 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.
|
||||
|
||||
If the number '''0''' is never generated as the first number in a loop, loop forever.
|
||||
<br><br>
|
||||
|
|
|
|||
39
Task/Loops-Break/360-Assembly/loops-break.360
Normal file
39
Task/Loops-Break/360-Assembly/loops-break.360
Normal 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
|
||||
7
Task/Loops-Break/Arc/loops-break.arc
Normal file
7
Task/Loops-Break/Arc/loops-break.arc
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(point break
|
||||
(while t
|
||||
(let x (rand 20)
|
||||
(prn "a: " x)
|
||||
(if (is x 0)
|
||||
(break)))
|
||||
(prn "b: " (rand 20))))
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
do
|
||||
a = int(rnd * 20)
|
||||
print a
|
||||
if a = 10 then exit loop 'EXIT FOR works the same inside FOR loops
|
||||
b = int(rnd * 20)
|
||||
print b
|
||||
loop
|
||||
REPEAT
|
||||
number = RANDOM(20)
|
||||
PRINT "first " ,number
|
||||
IF number = 0 THEN
|
||||
BREAK
|
||||
ENDIF
|
||||
PRINT "second ",RANDOM(20)
|
||||
UNTIL FALSE
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
10 FOR l = 1 TO 20
|
||||
20 IF l = 10 THEN LET l = 20: GO TO 40: REM terminate the loop
|
||||
30 PRINT l
|
||||
40 NEXT l
|
||||
50 STOP
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
10 LET a = INT (RND * 20)
|
||||
20 PRINT a
|
||||
30 IF a = 10 THEN STOP
|
||||
40 PRINT INT (RND * 20)
|
||||
50 GO TO 10
|
||||
do
|
||||
a = int(rnd * 20)
|
||||
print a
|
||||
if a = 10 then exit loop 'EXIT FOR works the same inside FOR loops
|
||||
b = int(rnd * 20)
|
||||
print b
|
||||
loop
|
||||
|
|
|
|||
5
Task/Loops-Break/BASIC/loops-break-4.basic
Normal file
5
Task/Loops-Break/BASIC/loops-break-4.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
10 FOR l = 1 TO 20
|
||||
20 IF l = 10 THEN LET l = 20: GO TO 40: REM terminate the loop
|
||||
30 PRINT l
|
||||
40 NEXT l
|
||||
50 STOP
|
||||
5
Task/Loops-Break/BASIC/loops-break-5.basic
Normal file
5
Task/Loops-Break/BASIC/loops-break-5.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
10 LET a = INT (RND * 20)
|
||||
20 PRINT a
|
||||
30 IF a = 10 THEN STOP
|
||||
40 PRINT INT (RND * 20)
|
||||
50 GO TO 10
|
||||
23
Task/Loops-Break/Bc/loops-break.bc
Normal file
23
Task/Loops-Break/Bc/loops-break.bc
Normal 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
|
||||
|
|
@ -1,17 +1,18 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
/*Corrected by Abhishek Ghosh, Mahalaya (19th September) 2017*/
|
||||
|
||||
#define LOWER 0
|
||||
#define UPPER 19
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
int main() {
|
||||
srand(time(NULL));
|
||||
time_t t;
|
||||
int a;
|
||||
srand((unsigned)time(&t));
|
||||
|
||||
for (;;) {
|
||||
unsigned a = LOWER + rand() / (RAND_MAX / (UPPER - LOWER + 1) + 1);
|
||||
a = rand()%20;
|
||||
printf("%d\n", a);
|
||||
if (a == 10) break;
|
||||
if (a == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
25
Task/Loops-Break/Dc/loops-break.dc
Normal file
25
Task/Loops-Break/Dc/loops-break.dc
Normal 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
|
||||
12
Task/Loops-Break/Gambas/loops-break.gambas
Normal file
12
Task/Loops-Break/Gambas/loops-break.gambas
Normal 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
|
||||
10
Task/Loops-Break/HolyC/loops-break.holyc
Normal file
10
Task/Loops-Break/HolyC/loops-break.holyc
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
U16 a, b;
|
||||
while (1) {
|
||||
a = RandU16 % 20;
|
||||
Print("%d\n", a);
|
||||
|
||||
if (a == 0) break;
|
||||
|
||||
b = RandU16 % 20;
|
||||
Print("%d\n", b);
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
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')
|
||||
);
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
17
|
||||
14
|
||||
3
|
||||
4
|
||||
13
|
||||
10
|
||||
15
|
||||
5
|
||||
10
|
||||
16
Task/Loops-Break/Jq/loops-break-1.jq
Normal file
16
Task/Loops-Break/Jq/loops-break-1.jq
Normal 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;
|
||||
3
Task/Loops-Break/Jq/loops-break-2.jq
Normal file
3
Task/Loops-Break/Jq/loops-break-2.jq
Normal 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);
|
||||
1
Task/Loops-Break/Jq/loops-break-3.jq
Normal file
1
Task/Loops-Break/Jq/loops-break-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def count(s): reduce s as $i (0; . + 1);
|
||||
45
Task/Loops-Break/OoRexx/loops-break.rexx
Normal file
45
Task/Loops-Break/OoRexx/loops-break.rexx
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*REXX ****************************************************************
|
||||
* Three Ways to leave a Loop
|
||||
* ooRexx added the possibility to leave an outer loop
|
||||
* without using a control variable
|
||||
* 12.05.2013 Walter Pachl
|
||||
**********************************************************************/
|
||||
do i1=1 To 2 /* an outer loop */
|
||||
Say 'i1='i1 /* tell where we are */
|
||||
Call random ,,123 /* seed to be reproducable */
|
||||
do forever /* inner loop */
|
||||
a=random(19)
|
||||
Say a
|
||||
if a=6 then leave /* leaces the innermost loop */
|
||||
end
|
||||
end
|
||||
|
||||
do i2=1 To 2
|
||||
Say 'i2='i2
|
||||
Call random ,,123
|
||||
do forever
|
||||
a=random(19)
|
||||
Say a
|
||||
if a=6 then leave i2 /* leaves loop with control variable i2 */
|
||||
end
|
||||
end
|
||||
|
||||
Parse Version v
|
||||
Select
|
||||
When pos('ooRexx',v)>0 Then supported=1
|
||||
Otherwise supported=0
|
||||
End
|
||||
If supported Then Do
|
||||
Say 'Leave label-name is supported in' v
|
||||
do Label i3 Forever
|
||||
Say 'outer loop'
|
||||
Call random ,,123
|
||||
do forever
|
||||
a=random(19)
|
||||
Say a
|
||||
if a=6 then leave i3 /* leaves loop with label name i3 */
|
||||
end
|
||||
end
|
||||
End
|
||||
Else
|
||||
Say 'Leave label-name is probably not supported in' v
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/*REXX program demonstrates a FOREVER DO loop with a test to LEAVE. */
|
||||
/*REXX program demonstrates a FOREVER DO loop with a test to LEAVE (break). */
|
||||
|
||||
do forever /*perform until da cows come home*/
|
||||
a=random(19) /*same as: random(0,19) */
|
||||
call charout ,right(a,5) /*show A right-justified, col. 1.*/
|
||||
if a==10 then leave /*Random#=10? Then cows went home*/
|
||||
b=random(19) /*same as: random(0,19) */
|
||||
say right(b,5) /*show B right-justified, col. 2.*/
|
||||
end /*forever*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
do forever /*perform loop until da cows come home.*/
|
||||
a=random(19) /*same as: random(0, 19) */
|
||||
call charout , right(a, 5) /*show A right─justified, column 1.*/
|
||||
if a==10 then leave /*is random #=10? Then cows came home.*/
|
||||
b=random(19) /*same as: random(0, 19) */
|
||||
say right(b, 5) /*show B right─justified, column 2.*/
|
||||
end /*forever*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
7
Task/Loops-Break/SPL/loops-break-1.spl
Normal file
7
Task/Loops-Break/SPL/loops-break-1.spl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
>
|
||||
n = #.rnd(20)
|
||||
#.output(n)
|
||||
<< n=10
|
||||
n = #.rnd(20)
|
||||
#.output(n)
|
||||
<
|
||||
8
Task/Loops-Break/SPL/loops-break-2.spl
Normal file
8
Task/Loops-Break/SPL/loops-break-2.spl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
>
|
||||
:1
|
||||
n = #.rnd(20)
|
||||
#.output(n)
|
||||
<-
|
||||
<< n=10
|
||||
1 <->
|
||||
<
|
||||
12
Task/Loops-Break/Simula/loops-break.simula
Normal file
12
Task/Loops-Break/Simula/loops-break.simula
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
! Loops/Break - simula67 - 08/03/2017;
|
||||
begin
|
||||
integer num,seed;
|
||||
seed:=0;
|
||||
while true do
|
||||
begin
|
||||
num:=randint(1,20,seed);
|
||||
outint(num,2); outimage;
|
||||
if num=10 then goto lab;
|
||||
end;
|
||||
lab:
|
||||
end
|
||||
6
Task/Loops-Break/Stata/loops-break.stata
Normal file
6
Task/Loops-Break/Stata/loops-break.stata
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
while 1 {
|
||||
local n=runiformint(0,19)
|
||||
display `n'
|
||||
if `n'==10 continue, break
|
||||
display runiformint(0,19)
|
||||
}
|
||||
8
Task/Loops-Break/Transact-SQL/loops-break.sql
Normal file
8
Task/Loops-Break/Transact-SQL/loops-break.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
DECLARE @i INT;
|
||||
WHILE 1=1
|
||||
BEGIN
|
||||
SET @i = ABS(CHECKSUM(NewId())) % 20;
|
||||
PRINT @i;
|
||||
IF @i=10 BREAK;
|
||||
PRINT ABS(CHECKSUM(NewId())) % 20;
|
||||
END;
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
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 a, b, i
|
||||
|
||||
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
|
||||
Do
|
||||
a = Int(Rnd * 20)
|
||||
WScript.StdOut.Write a
|
||||
If a = 10 Then Exit Do
|
||||
b = Int(Rnd * 20)
|
||||
WScript.Echo vbNullString, b
|
||||
Loop
|
||||
|
||||
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
|
||||
|
|
|
|||
3
Task/Loops-Break/Zkl/loops-break.zkl
Normal file
3
Task/Loops-Break/Zkl/loops-break.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
while(1){n:=(0).random(20); n.print(" ");
|
||||
if (n==10){ println(); break; } (0).random().println();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue