Prev: is this NP-Hard?
Next: An M/M/n queuing model simulation with Object Pascal and my Thread Pool Engine...
From: red floyd on 25 Apr 2010 02:19 On 4/24/2010 5:54 PM, Andrew Poelstra wrote: > The alternative here, using the loop structure, would be: > > for(i = 0; i< 10&& arr[i].state != READY; ++i) > ; > /* now use arr[i], or if i is 10, indicate failure. */ > As a purely stylistic matter, my empty loops always look like: for ( begin_expr; test_expr; next_expr) /* do nothing */ ; That is, I always explicitly comment the empty loop so that it's clear that I wanted the loop to be empty. Makes life easier later on down the line.
From: Juha Nieminen on 25 Apr 2010 03:02 In comp.lang.c++ red floyd <no.spam.here(a)its.invalid> wrote: > As a purely stylistic matter, my empty loops always look like: > > for ( begin_expr; test_expr; next_expr) > /* do nothing */ ; No, the proper way of writing an empty loop is: for(begin_expr; test_expr; next_expr) {} The empty block makes it explicitly clear that it's intended to be empty, and not just a typo. (The empty block could also be put in the next line, below the 'for', if so desired. A matter of style.)
From: Lie Ryan on 27 Apr 2010 15:18 On 04/25/10 16:19, red floyd wrote: > On 4/24/2010 5:54 PM, Andrew Poelstra wrote: > >> The alternative here, using the loop structure, would be: >> >> for(i = 0; i< 10&& arr[i].state != READY; ++i) >> ; >> /* now use arr[i], or if i is 10, indicate failure. */ >> > > As a purely stylistic matter, my empty loops always look like: > > > for ( begin_expr; test_expr; next_expr) > /* do nothing */ ; > > That is, I always explicitly comment the empty loop so that > it's clear that I wanted the loop to be empty. > Stylistically, I would put an empty { } to the side, containing a single space: for ( begin_expr; test_expr; next_expr) { } instead of semicolons. Most brace-language programmer would unconsciously filter out semicolons from the end of lines, while { } is much more visible since it's more unusual to open a block only to close it again.
From: Nick Keighley on 28 Apr 2010 03:26 On 25 Apr, 08:02, Juha Nieminen <nos...(a)thanks.invalid> wrote: > In comp.lang.c++ red floyd <no.spam.h...(a)its.invalid> wrote: > > As a purely stylistic matter, my empty loops always look like: > > > for ( begin_expr; test_expr; next_expr) > > /* do nothing */ ; > > No, the proper way of writing an empty loop is: alarm bells go off whenever I see a sentence of the form "the proper way to..." > for(begin_expr; test_expr; next_expr) {} > > The empty block makes it explicitly clear that it's intended to be empty, > and not just a typo. (The empty block could also be put in the next line, > below the 'for', if so desired. A matter of style.) for (begin_expr; test_expr; next_expr) ; is my usual form. And I cam across this and was taken with it for (begin_expr; test_expr; next_expr) continue; (the place I'd comtemplate a continue)
From: Kenneth Brody on 28 Apr 2010 09:35 On 4/28/2010 3:26 AM, Nick Keighley wrote: > On 25 Apr, 08:02, Juha Nieminen<nos...(a)thanks.invalid> wrote: >> In comp.lang.c++ red floyd<no.spam.h...(a)its.invalid> wrote: > >>> As a purely stylistic matter, my empty loops always look like: [... snip "the right way" to write empty loop ...] > > for (begin_expr; test_expr; next_expr) > ; > > is my usual form. And I cam across this and was taken with it > > for (begin_expr; test_expr; next_expr) > continue; > > (the place I'd comtemplate a continue) We can discuss "the right way" til the cows come home. However, I think we'd probably all agree that this is "the wrong way": for ( begin ; test ; next ); Yes, I've seen it, numerous times, in someone's code. Even worse is when different editors have caused tab misalignment, and you end up with: for ( begin ; test ; next ); if ( this ) do_that(); (I've seen that, too.) -- Kenneth Brody
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: is this NP-Hard? Next: An M/M/n queuing model simulation with Object Pascal and my Thread Pool Engine... |