C++ Logo

std-proposals

Advanced search

Re: dofor loop

From: Matthew Woehlke <mwoehlke.floss_at_[hidden]>
Date: Mon, 30 Dec 2019 15:57:26 -0500
On 27/12/2019 14.44, John Yates via Std-Proposals wrote:
> If `do` were to get an optional init-statement and `while` an optional
> increment-statement then you could have:
>
> do [ (init-statement) ]
> {
> ...statements...
> } while (condition [ ; increment-statement ] )

I wouldn't mind `while (cond; incr)` either, especially if it extends to
non-do loops (yes, even though that's just `for (; cond; incr)`, because
IMHO that's ugly and I tend to try to avoid it as a result).

Actually, I just realized, if we *could* get this, it would help with
another long-standing request... namely:

  do (auto something = decl)
  {
    ...statements...
  } while (false)

...which is still a little ugly, but less so IMHO than a bare block. If
nothing else, it would (slightly) simplify the body of my `#define
with(expr)`.

-- 
Matthew

Received on 2019-12-30 14:59:57