3 ms·
The while+switch, to me, looks like goto with extra typing. state = START; break; Translates directly to: goto start; Except while+switch is nic
by klodolph 9y ago
The while+switch, to me, looks like goto with extra typing.
state = START;
break;
Translates directly to:
goto start;
Except while+switch is nicer if you have transition tables. YMMV
- marcosdumay 9y agoYes, but it forces you to keep your state as data, and makes it much more clear how the data relates to the code. But it does make for the same exact behavior.
- klodolph 9y agoThe state is data either way... either an explicit variable or the program counter. With goto, the compiler is more likely to be able to see across state change boundaries (e.g. phi() will work correctly without doing anything fancy). So you can, e.g., have the compiler help you out by giving you warnings for uninitialized variables, when the variables are initialized in one state and used in another.