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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -