Beeflang - open source performance-oriented compiled programming language
jmh530
john.michael.hall at gmail.com
Thu Jan 9 17:41:31 UTC 2020
On Thursday, 9 January 2020 at 17:19:38 UTC, Gregor Mückl wrote:
> [snip]
>
> do {} has a separate meaning in beef. These blocks are not
> looping, but using break; is valid in them to skip to their
> end. While this is certainly creative, I don't know if it all
> that useful. But it burns the "do" keyword in the grammar and
> something else is required to start a do/while block.
I think his point is that do {} while(false) is basically a
non-looping do statement. So you can use breaks within it like
below (adapting the example from beeflang.org). The only
difference I can see is that you can return from Beef's do
statement. There's probably a way to do that in D, but I haven't
thought a lot about it.
void main() {
int result;
do {
int c = 2;
if (c == 0)
break;
string op = "+";
if (op != "+")
break;
int c2 = 3;
if (c2 == 0)
break;
result = c + c2;
} while (false);
assert(result == 5);
}
More information about the Digitalmars-d
mailing list