fork download
  1. #include <iostream>
  2.  
  3. enum statetype {firststate, secondstate, stopstate};
  4.  
  5. void dofirststate() {
  6. //does stuff
  7. std::cout << "HI! ";
  8. throw secondstate;
  9. }
  10.  
  11. void dosecondstate() {
  12. //does stuff
  13. std::cout << "BYE!";
  14. throw stopstate;
  15. }
  16.  
  17. int main() {
  18. statetype curstate = firststate;
  19. while (curstate!= stopstate) {
  20. try {
  21. switch (curstate) {
  22. case firststate: dofirststate();
  23. case secondstate: dosecondstate();
  24. }
  25. } catch(statetype& s) {
  26. curstate = s;
  27. }
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2960KB
stdin
Standard input is empty
stdout
HI! BYE!