Subj : Re: Syntax, style, the infinite monkey theorum and coding To : comp.programming From : CBFalconer Date : Tue Aug 23 2005 04:33 pm Gerry Quinn wrote: > m.fee@iirrll..ccrrii..nnzz says... >> gerryq@DELETETHISindigo.ie says... > >>> I can imagine that being a viable style in some cases, i.e. >>> where there are several independent conditions that break the >>> loop and each needs a comment: >>> >>> while( condition1 // comment >>> && condition2 // comment >>> && condition3 // comment >>> ) >>> { >>> // do stuff >>> } > >> My preferred style would be something like... >> >> function Peculiar_Conditions(some arguements) : boolean; >> begin >> result := condition1 //comment >> and condition2 //comment >> and condition3; //comment >> end; >> >> ... >> >> while Peculiar_Conditions(some arguements) do >> begin >> do stuff >> end; >> >> Thus separating out the conditional logic from the rest of the >> program flow. > > PeculiarConditions() is an option, particularly if they really > have some particular meaning, i.e. something that is simply > stated but needs a lot of testing to find out. > > I prefer the style: > > while( true ) > { > if ( ! condition1 ) break; > if ( ! condition2 ) break; > // do stuff > } > > But not everyone likes that either. And I would use: if (!condition1) failure(1); else if (!condition2) failure(2); else if (!condition3) failure(3); else { /* all well */ dostuff(); } -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson .