Repeat: Difference between revisions

576 bytes added ,  3 years ago
Add Cowgol
(use nim lang tag after all)
(Add Cowgol)
Line 401:
 
(repeat (lambda () (format T "Example~%")) 5)</lang>
 
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
 
# Only functions that implement an interface can be passed around
# The interface is a type and must be defined before it is used
# This defines an interface for a function that takes no arguments
interface Fn();
 
# This function repeats a function that implements Fn
sub Repeat(f: Fn, n: uint32) is
while n != 0 loop
f();
n := n - 1;
end loop;
end sub;
 
# Here is a function
sub Foo implements Fn is
print("foo ");
end sub;
 
# Prints "foo foo foo foo"
Repeat(Foo, 4);
print_nl(); </lang>
 
=={{header|D}}==
2,114

edits