Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #1905 > unrolled thread
| Started by | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| First post | 2012-07-06 14:29 +0100 |
| Last post | 2012-07-06 14:29 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.programming
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: repeating something n times Rui Maciel <rui.maciel@gmail.com> - 2012-07-06 14:29 +0100
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2012-07-06 14:29 +0100 |
| Subject | Re: repeating something n times |
| Message-ID | <jt6p73$ffe$1@speranza.aioe.org> |
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 top | Article view | comp.programming
csiph-web