Repeat: Difference between revisions

1,768 bytes added ,  25 days ago
m
m (Create a repetition example in Mastermind.)
 
(3 intermediate revisions by 3 users not shown)
Line 327:
 
=={{header|Applesoft BASIC}}==
https://web.archive.org/web/20190202165511/http://hoop-la.ca/apple2/2016/winterwarmup/#repeat.bas
<syntaxhighlight> 100 FOR I = 768 TO 794
110 READ B: POKE I,B: NEXT
120 DATA165,185,72,165,184,72
130 DATA165,118,72,165,117,72
140 DATA169,176,72,32,123,221
150 DATA32,82,231,32,65,217
160 DATA76,210,215
170 POKE 1014,0: POKE 1015,3
 
200 LET P = 400:N = 4
210 GOSUB 300"REPEAT P N
220 END
 
300 IF N < = 0 THEN RETURN
310 LET N = N - 1
320 & P
330 GOTO 300
 
400 PRINT "EXAMPLE"
410 RETURN
</syntaxhighlight>
 
=={{header|Arturo}}==
Line 652 ⟶ 673:
{{works with|C++11}}
<syntaxhighlight lang="cpp"> repeat([]{std::cout << "Example\n";}, 4);</syntaxhighlight>
 
=={{header|Chapel}}==
 
The most basic form, with generics.
<syntaxhighlight lang="chapel">
config const n = 5;
 
proc example()
{
writeln("example");
}
 
proc repeat(func, n)
{
for i in 0..#n do func();
}
 
repeat(example, n);
</syntaxhighlight>
 
With argument type hinting.
<syntaxhighlight lang="chapel">
config const n = 5;
 
proc example()
{
writeln("example");
}
 
proc repeat(func : proc(), n : uint)
{
for i in 0..#n do func();
}
 
repeat(example, n);
</syntaxhighlight>
 
Example of passing function which takes arguments. Chapel does not allow functions with generic arguments to be passed. First-class functions are still in development: https://chapel-lang.org/docs/technotes/firstClassProcedures.html
<syntaxhighlight lang="chapel">
config const n = 5;
 
proc example(x : uint)
{
writeln("example ", x);
}
 
proc repeat(func : proc(x : uint), n : uint)
{
for i in 0..#n do func(i);
}
 
repeat(example, n);
</syntaxhighlight>
 
=={{header|Clojure}}==
Line 1,963 ⟶ 2,037:
hello
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Repeat 3 Example> Eggs And <Example>>;
}
 
Repeat {
0 s.F e.X = e.X;
s.N s.F e.X = <Repeat <- s.N 1> s.F <Mu s.F e.X>>;
};
 
Example {
e.X = e.X Spam;
};</syntaxhighlight>
{{out}}
<pre>Spam Spam Spam Eggs And Spam</pre>
 
=={{header|REXX}}==
6

edits