goto a no-go?

monarch_dodra monarchdodra at gmail.com
Wed Oct 2 01:15:03 PDT 2013


On Wednesday, 2 October 2013 at 06:19:24 UTC, Jakob Ovrum wrote:
> On Tuesday, 1 October 2013 at 17:15:34 UTC, Ali Çehreli wrote:
>> Nobody mentioned the use of goto with switch-case.
>
> Those are goto-case statements, not goto statements. I don't 
> think it's a useful notion to associate the two beyond the fact 
> that they share a keyword in their syntax.

Well, it remains a "go to this piece of code" command.

Now, you can write a program as a single giant switch that jumps 
around from state to state, without it ever ending. Like in one 
of those "read your own adventure books"

int page = 1;
switch(1)
{
     case 1:
     writeln("you arrive in a large chamber...
                 To light a torch, go to page 196)
                 To run through, go to page 155";
     readfln("%s", &page);
     goto page;

     etc...
}

That's a pretty sweet construct actually :)


More information about the Digitalmars-d mailing list