On Fri, Jul 12, 2002 at 10:43:46AM +0100, Angus Leeming wrote:
> Another coding question. Can I write this loop another, more elegant  way?
> Angus
> 
>       // visible contains pointers to the first and last rows visible in 
>       // the BufferView
>       std::pair<Row const *, Row const *> visible = ...
> 
>       bool running = true;
>       for (Row const * row = visible.first; running; row = row->next()) {
>               do what you want to do...
> 
>               running = row != visible.second;
>       }

for (Row const * row = visible.first; row != visible.second; row = row->next()) {
                do what you want to do...
}

is slightly different (might have 0 loops) but depending on what you do it
could be the same. If not I'd write that as

for (Row const * row = visible.first; true; row = row->next()) {
         // do what you want to do...
   if (row != visible.second)
     break;
}

saves one "global" variable but uses 'break' which some people frown upon
(mostly for reasons I don't accept...)

Andre'


-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)

Reply via email to