/*************** ******** Improve the following program fragments through reorganization. ****************/ while(A) { if(B) continue; C; } //To........................... while(A) if(!B) C; //next -------------------------------- // The big difference between a do while and while loop is that the do while will // execute at lest once, while a while loop may not execute at all. do { if(!A) continue; else B; C; } while(A); //To....................... // Can't use a while loop if 'B' or 'C' affects 'A' existences. do{ if(A) {B; C;} } while(A) // If 'B and C' do not affect 'A' then you can use a while loop. while(A) { B; C; } //next ---------------------------------- if(A) if(B) if(C) D; else; else; else if(B) if(C) E; else F; else; } //To............................. // What the intent is // If A, B, C, exist then do D. // If one or all of A, B, C, are false then do not do D. // If B, and C exist do E. // If B exits but C is false do F. // This is close, but must check A's condition in second if. if(A && B && C) D; else if(B && C) E; else if(B) F; // To............................ // This uses 3 if and 2 else. if(A && B && C) D; else if(!A && B && C) E; else if(!A && B && !C) F; //next ---------------------------------------- while( (c=getchar()) !='\n' ) { if( c==' ' ) continue; if( c=='\t' ) continue; if( c<'0' ) return(OTHER); if( c<'9' ) return(DIGIT); if( c<'a' ) return(OTHER); if( c<'z' ) return(ALPHA); return (OTHER); } return(EOL); // To............................. // Feuer solution. while( (c=getchar()) != '\n' ) { if( c>='a' && c<='z' ) return ALPHA; else if( c>='0' && c<='9' ) return DIGIT; else if( c!=' ' && c!='\t' ) return OTHER; } return (EOL); // This may work too. while( (c=getchar()) !='\n') { switch( c ) { case ' ' : continue; break; case '\t': continue; break; case '0' : return(OTHER); break; case '9' : return(DIGIT); break; case 'a' : return(OTHER); break; case 'z' : return(ALPHA); break; default (OTHER); } } return(EOL); //next ---------------------------------------- done = i = 0; while( i1 ) { i++; continue; } done++; } // To.................................. // Feuer puts it all in one 'for' statement. for(i=0; i1; i++ ) ; //next ---------------------------------------- plusflg = zeroflg = negflg =0; if( a>0 ) ++plusflg; if( a==0 ) ++zeroflg; else if( !plusflg ) ++negflg; // To............................................ plusflg = zeroflg = negflg =0; if( a>0 ) ++plusflg; else if( a==0 ) ++zeroflg; else if( !plusflg ) ++negflg; //next ----------------------------------------- if(A) { B; return; } if(C) { D; return; } if(E) { F; return; } G; return; // To........................................... if(A) B; else if(C) D; else if(E) F; else G; return; //next ----------------------------------------- i=0; while((c=getchar())!=EOF) { if(c!='\n'||c!='\t') {[i++]=c;continue;} if(c=='\n') break; if(c=='\t') c=' '; s[i++]=c;} // To........................................... for( i=0; (c=getchar())!=EOF && c!='\n'; i++ ) s[i] = c!='\t' ? c : ' '; //next ----------------------------------------- if( x!=0 ) if( j>k ) y=j/x; else y=k/x; else if( j>k ) y=j/NEARZERO; else y=k/NEARZERO; } // To (mine)............................................ if( x!=0 && j>k ) y=j/x; else y=k/x; else (j>k) ? y=j/NEARZERO : y=k/NEARZERO; // Feuer has two rewrights. /* In this problem it is quite clear that x!=0 is not the primary idea; the test simply protects against division by zero. The conditional nicely subordinates the zero check. */ 1). if( j>k ) y = j / (x!=0 > x : NEARZERO); else y = k / (x!=0 > x : NEARZERO); /* //OR A case can be made that the assignment to y is the primary idea, subordinating both test. (MAX returns the greater of its two arguments.) */ 2). y = MAX(j,k) / (x!=0 ? x : NEARZERO);