Originally posted by Vber
Ok Prelude, so there is something that it's possible to do with gotos and impossible in another way? I don't think so...
The point isn't that it's possible only using goto, but rather that rarely it may be more benificial to do so.
Consider a hugely nested loop set. You could "break out of" them all by adding extra conditioinal checks to each loop break:
Code:
for( foo = bar; bar < fwee && exit_status != something; stuff++ )
for( fie = foe; foe < fum && exit_status != something; add_naseum++ )
for( this = that; the == other_thing && exit_status != something; morethings++ )
Repeat that a few dozen more times, and you've just added a slew of checks each time every loop executes. A single goto statement would improve performance here. I think that's the point anyway.
However, that being said, back to the original request:
Code:
switch( toupper( input[0] ) )
{
case 'A':
if( strcmp( input, "Alpha" ))
{
}
else
if( strcmp( input, "Apple" ) )
{
}
else
....
break;
case 'B':
if( strcmp( input, "Ball" ))
{
}
else
if( strcmp( input, "Bravo" ) )
{
}
else
....
break;
....
}
There's one way to parse input. As I've already mentioned, The Mud Connector is a good resource for the original poster. You'll commonly see the DIKU variety typically implement a FSM (Finite State Machine) which uses a similar approach:
Code:
switch( descriptor->state )
{
case CON_CONNECTING:
...
break;
case CON_DISCONNECT:
...
break;
case CON_NEW_PLAYER:
...
break;
case CON_PICK_RACE:
...
break;
....
}
Something similar to the above. The switch it in an infinite loop, and basicly, it just takes your current state and parses your input accordingly.
Quzah.