while ( true )
{
eof = read_file();
if ( eof ) break;
/* ... do something ... */
}
/* ... continue ... */
and here is the same example using labels and the goto statement
read_file_next_element: eof = read_file(); if ( eof ) goto read_file_eof; /* ... do something ... */ goto read_file_next_element; read_file_eof: /* ... continue ... */
Notice that with meaningful label names, the code becomes self documenting (I say that rather loosely btw!).
The history behind the animosity toward labels and goto statements actually stems from the days when memory for compilation was so limited, programmers had little choice but to write the code as follows:
l1: eof = read_file(); if ( eof ) goto l2; /* ... do something ... */ goto l1; l2: /* ... continue ... */
What are your thoughts on this rather explosive topic?
This post has been edited by Martyn.Rae: 25 January 2010 - 06:15 AM

New Topic/Question
Reply


MultiQuote
















|