c++ - header for loop same as body duplicate code -


i'm trying output 2d table file, including header row , column. rather not check in loop if it's header file, distracting reader; rather not write inner loop twice because fear may accidentally diverge in maintenance. both loops spanning range in double, use integer in parallel avoid round off problems @ loop end.

below code 'header row condition' i<0 in loop.

xi = range.xi.min(); for(int = -1; i< 128; i++, xi += range.xi/128) {     if(i<0)                                                  file.write( format_blank, strlen(format_blank) );       // write top corner of table     else                                             write( file, format_nth_csv, xi );                      // write 1st column      dxi = range.dxi.min();     for(int j=0; j < 64; j++, dxi += range.dxi/64) {         if (i<0)                                             write( file, format_1st_csv, dxi);                  // write header row         else                                                         write( file, format_nth_csv, kerneldensity.evaluatedat( xi, dxi ) );// write table contents     } } 
  1. is compiler smart enough unwrap header pass @ loop?
  2. is readable? or better separated header loop , body loop?


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -