Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most elegant way to loop TWICE in C

Tags:

iterator

c

loops

Many times I need to do things TWICE in a for loop. Simply I can set up a for loop with an iterator and go through it twice:

for (i = 0; i < 2; i++)
{
 // Do stuff
}

Now I am interested in doing this as SIMPLY as I can, perhaps without an initializer or iterator? Are there any other, really simple and elegant, ways of achieving this?

like image 443
Xofo Avatar asked Sep 06 '25 08:09

Xofo


1 Answers

This is elegant because it looks like a triangle; and triangles are elegant.

i = 0; 
here: dostuff(); 
i++; if ( i == 1 ) goto here;
like image 88
Ilan Avatar answered Sep 07 '25 23:09

Ilan