goto a no-go?

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Wed Oct 2 09:12:57 PDT 2013


On Tuesday, 1 October 2013 at 11:26:54 UTC, Dicebot wrote:
>> // ...
>> if (word.length == 1) goto FormatOutput;
>>
>> // if word.length > 1, some extra work has to be done
>> // initialize some variables, parse, do some processing etc.
>>
>> FormatOutput:
>> // .....
>>
>> return output;
>
> Have never felt need to use `goto` since got familiar with 
> `scope(something)` : http://dpaste.dzfl.pl/ca40b3b6
>
> ;)

     if (word.length)
         scope(exit) FormatOutput();

This is the same as

     if (word.length)
         FormatOutput();

The `if` introduces a new scope, thus running the code right away.


More information about the Digitalmars-d mailing list