What is the most elegant way to loop TWICE in C

Encapsulate it in a function and call it twice.

void do_stuff() {
  // Do Stuff
}

// .....

do_stuff();
do_stuff();

Note: if you use variables or parameters of the enclosing function in the stuff logic, you can pass them as arguments to the extracted do_stuff function.


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

i = 0; 
here: dostuff(); 
i++; if ( i == 1 ) goto here;

If its only twice, and you want to avoid a loop, just write the darn thing twice.

statement1;
statement1;  // (again)

Tags:

C

Loops

Iterator