Repeat: Difference between revisions

16 bytes added ,  10 years ago
Examples now in alphabetical order. Made a draft task (I presume that was wanted)?
(created in three langs, in incorrect alphabetical order)
 
(Examples now in alphabetical order. Made a draft task (I presume that was wanted)?)
Line 1:
{{draft task}}
The task is to write a procedure wichwhich accepts as arguments another procedure and a positive integer. The latter procedure is executed a number of times equal to the accepted integer.
 
=={{header|PythonC}}==
<lang PythonC>
#include <stdio.h>
#!/usr/bin/python
def repeat(f,n):
for i in range(n):
f();
 
void repeat(void (*f)(void), int n) {
def procedure():
for(int i=n; 0<i; i--)
print("Example");
(*f)();
 
void example() {
repeat(procedure,3); #prints "Example" (without quotes) three times, separated by newlines.
printf("Example\n");
 
void main(char *argv[], int argc) {
repeat(example, 4);
</lang>
 
 
=={{header|Haskell}}==
<lang Haskell>
Line 26 ⟶ 33:
</lang>
 
=={{header|CPython}}==
<lang CPython>
#!/usr/bin/python
#include <stdio.h>
def repeat(f,n):
for i in range(n):
f();
 
def procedure():
void repeat(void (*f)(void), int n) {
print("Example");
for(int i=n; 0<i; i--)
(*f)();
 
repeat(procedure,3); #prints "Example" (without quotes) three times, separated by newlines.
void example() {
printf("Example\n");
 
void main(char *argv[], int argc) {
repeat(example, 4);
</lang>
Anonymous user