[Language construct idea] The for loop with prepare step

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Feb 13 00:59:36 UTC 2024


On 13/02/2024 6:52 AM, H. S. Teoh wrote:
> One example of the usefulness of a loop construct that supports the 
> above construct in full generality is the outputing of list delimiters. 
> If we postulate a syntax construct like:
> 
> 
> |loop { loopBodyBeforeCondition(); } while(cond) { 
> loopBodyAfterCondition(); } |
> 
> 
> then, given some range r of items, we can output it with delimiters like 
> this:
> 
> 
> |loop { writef("%s", r.front); r.popFront; } while(!r.empty) { write(", 
> "); } |

Oh I quite like this.

```d
do {
} while(cond) {
}
```

```d
foreach(...) {

} while {

}
```

I would use this a lot.


More information about the Digitalmars-d mailing list