>>66
And here's the same FSM but slightly less verbose. I've removed the "else" statements and allowed the cases to fall through each other. This lowers the readability, but uses less code. The readability now becomes more like your original example in
>>64 while still requiring no goto statements.
char state = 'a';
int stopped = 0;
while(!stopped)
{
switch(state)
{
case 'a':
do1();
case 'b':
if(do2())
{
state = 'a';
break;
}
case 'c':
if(do3())
{
state = 'b';
break;
}
case 'd':
if(do4())
{
state = 'c';
break;
}
case 'e':
if(do5())
{
state = 'd';
break;
}
default:
// quit
stopped = 1;
}
}