June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,9 +1,25 @@
|
|||
;Task:
|
||||
Show a loop which prints random numbers (each number newly generated each loop) from '''0''' to '''19''' (inclusive).
|
||||
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.
|
||||
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 '''0''' is never generated as the first number in a loop, loop forever.
|
||||
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]]
|
||||
<br><br>
|
||||
|
|
|
|||
25
Task/Loops-Break/ALGOL-60/loops-break.alg
Normal file
25
Task/Loops-Break/ALGOL-60/loops-break.alg
Normal 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'
|
||||
|
|
@ -2,6 +2,6 @@
|
|||
(while t
|
||||
(let x (rand 20)
|
||||
(prn "a: " x)
|
||||
(if (is x 0)
|
||||
(if (is x 10)
|
||||
(break)))
|
||||
(prn "b: " (rand 20))))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
REPEAT
|
||||
number = RANDOM(20)
|
||||
PRINT "first " ,number
|
||||
IF number = 0 THEN
|
||||
IF number = 10 THEN
|
||||
BREAK
|
||||
ENDIF
|
||||
PRINT "second ",RANDOM(20)
|
||||
|
|
|
|||
|
|
@ -2,17 +2,15 @@
|
|||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
|
||||
int main()
|
||||
{
|
||||
srand(time(0));
|
||||
while(true)
|
||||
{
|
||||
int a = 0 + rand() % 19;
|
||||
std::cout << a << std::endl;
|
||||
if (a == 10)
|
||||
break;
|
||||
int b = 0 + rand() % 19;
|
||||
std::cout << b << std::endl;
|
||||
}
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,14 @@
|
|||
/*Corrected by Abhishek Ghosh, Mahalaya (19th September) 2017*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
int main() {
|
||||
int main(){
|
||||
time_t t;
|
||||
int a;
|
||||
srand((unsigned)time(&t));
|
||||
|
||||
for (;;) {
|
||||
a = rand()%20;
|
||||
printf("%d\n", a);
|
||||
if (a == 0) break;
|
||||
}
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ while (1) {
|
|||
a = RandU16 % 20;
|
||||
Print("%d\n", a);
|
||||
|
||||
if (a == 0) break;
|
||||
if (a == 10) break;
|
||||
|
||||
b = RandU16 % 20;
|
||||
Print("%d\n", b);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
/*REXX program demonstrates a FOREVER DO loop with a test to LEAVE (break). */
|
||||
|
||||
/*REXX program demonstrates a FOREVER DO loop with a test to LEAVE (break). */
|
||||
/*REXX's RANDOM BIF returns an integer.*/
|
||||
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*/
|
||||
end /*forever*/ /* [↑] CHAROUT , xxx writes to term.*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
5
Task/Loops-Break/Stata/loops-break-2.stata
Normal file
5
Task/Loops-Break/Stata/loops-break-2.stata
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
for (; 1; ) {
|
||||
printf("%f\n",n=runiformint(1,1,0,19))
|
||||
if (n==10) break
|
||||
printf("%f\n",runiformint(1,1,0,19))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue