Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #1905

Re: repeating something n times

Path csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From Rui Maciel <rui.maciel@gmail.com>
Newsgroups comp.programming
Subject Re: repeating something n times
Date Fri, 06 Jul 2012 14:29:09 +0100
Organization Aioe.org NNTP Server
Lines 37
Message-ID <jt6p73$ffe$1@speranza.aioe.org> (permalink)
References <repeat-20120705210751@ram.dialup.fu-berlin.de>
Reply-To rui.maciel@gmail.com
NNTP-Posting-Host AqItoBXOUTdaiWbH4r55cA.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Complaints-To abuse@aioe.org
User-Agent KNode/4.8.4
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.programming:1905

Show key headers only | View raw


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


Thread

Re: repeating something n times Rui Maciel <rui.maciel@gmail.com> - 2012-07-06 14:29 +0100

csiph-web