3 ms·
My favorite use of goto is with C#'s "yield return". The compiler converts a function with a yield command into a label. To resume a function from where it lef
by billpg 5y ago
My favorite use of goto is with C#'s "yield return".
The compiler converts a function with a yield command into a label. To resume a function from where it left off, the compiler adds code to test an added resumption-point variable and to goto the label for each resumption point.
- heavenlyblue 5y agoAll code that ends up being written as assembly will become a command (an opcode or a set of opcodes) and a label (the opcode's address).
- fjfaase 5y agoI have used the goto statement to implement enumerators classes in C++ using a state member and a switch statement with goto statements at the start of the method. Of course, also all local (loop) variables need to be replaced by (private) members. At each 'yield' location, you set the state variable, have a return statement, followed by a label. It is also possible to do this in C with functions and structs. See for example: https://www.iwriteiam.nl/Ha_cmt.html https://www.iwriteiam.nl/Ha_cmt.html