'goto', as an indicator of good language

jmh530 john.michael.hall at gmail.com
Fri Sep 9 10:34:13 UTC 2022


On Friday, 9 September 2022 at 09:30:21 UTC, JN wrote:
> On Thursday, 8 September 2022 at 22:47:33 UTC, Walter Bright 
> wrote:
>> To be fair, nested functions along with function inlining has 
>> eliminated many of the reasons that I use gotos.
>>
>> Another reason for gotos is for ways of exiting loops without 
>> having to set flags that later control the flow.
>
> I find it surprising that no language added something like 
> "break all;" instruction to exit all loops.

D can break on labels, which is even more powerful than that. To 
be honest, I don't recall ever using it in my own code, but it 
works.

```d

import core.stdc.stdio: printf;

void main()
{
     outer: for (size_t i = 0; i < 4; i++) {
         for (size_t j = 0; j < 4; j++) {
             if (i * j > 4) {
              	break outer;
             }
          	printf("i = %lu, j = %lu\n", i, j);
         }
         printf("i = %lu\n", i);
     }
}
```


More information about the Digitalmars-d mailing list