Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #1905
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: repeating something n times |
| Date | 2012-07-06 14:29 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jt6p73$ffe$1@speranza.aioe.org> (permalink) |
| References | <repeat-20120705210751@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
> to repeat something 4 times, but in C one needs
>
> for( int i = 0; i < 3; ++i )
>
> , where the need to introduce a variable in the source code
> seems redundant in this case and more troublesome and error-prone.
<code lang="C">
#include <stdio.h>
void repeat(unsigned int i, void routine(void))
{
(*routine)();
if(i > 1)
repeat(i-1, routine);
}
void print(void)
{
puts("This is fun");
}
int main(void)
{
repeat(4, &print);
return 0;
}
</code>
A for() loop is much nicer.
Rui Maciel
Back to comp.programming | Previous | Next | Find similar | Unroll thread
Re: repeating something n times Rui Maciel <rui.maciel@gmail.com> - 2012-07-06 14:29 +0100
csiph-web