C++ Logo

std-proposals

Advanced search

Re: [std-proposals] !continue

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Mon, 6 Nov 2023 19:54:03 +0100
pon., 6 lis 2023 o 18:37 Bjorn Reese via Std-Proposals
<std-proposals_at_[hidden]> napisaƂ(a):
>
> On 11/6/23 00:25, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> > Bjorn wrote:
> >> The usual solution is to move the increment into the loop
> >>
> >> while (Serial.available()) {
> >> // Do stuff
> >> if (condition) {
> >> // Do conditional stuff
> >> p = buf;
> >> } else {
> >> ++p;
> >> }
> >> }
> >
> >
> > Again here you're losing the simplicity of having 'continue' in other
> > places in the loop (if the loop were bigger and more complex).
>
> The following minor refactoring is very close to what you ask,
> without introducing new language features:
>
> while (Serial.available()) {
> // Do stuff
> if (condition) {
> // Do conditional stuff
> p = buf;
> continue;
> }
> ++p;
> }
>

Another question is why use raw pointers in the first place?

```
while (Serial.available())
{
    if (!static_string.have_free_space()) break;
    static_string.push_back(Serial.read());
    if (static_string.end_with("\r\n"))
    {
        static_string.pop_end();
        static_string.pop_end();
        if (!static_string.empty()) process(static_string.data());
        static_string.clear();
    }
}
```

clean, simple and is working now.

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-11-06 18:54:16