c++ - Most elegant looping construct? -
sorry newb question. i'm still learning programming. i'm using c++, , need this:
int n; { n = get_data(); if(n != -1) send(n); } while(n != -1);
this sketch. anyway doesn't feel real elegant. have have test twice. test once , set flag, doesn't feel real elegant either since have check flag twice. seems there should way more easily, since it's easy want do.
int n; while (-1 != (n = get_data())) { send(n); } // while
Comments
Post a Comment