Recently, for the programming class, we were given the task of writing a program in any language, which, given n, will cause all possible violations for an array p of size n, such that p [i]! = I for all i: 0 <= i <n We had to use iterators, for example. yield .
Example: n = 3, [0, 1, 2] is not a disorder, but [2, 0, 1] is also equal to [1, 2, 0].
I came up with a pseudo-code solution that would work, but the problem was that it required power loops (i.e. n nested loops where n is known only at runtime). To do this, I generated n nested loops in the Ruby code in the string, and then eval in the string. My solution worked, however my professor believed that using multiple goto would be a better solution (easier to read, at least) than creating dynamic code.
I got the impression that goto always a bad choice. Why can estimating the runtime of dynamically generated code be worse than goto ? The generated code is clean and simple and seems pretty effective for this problem. The only user input that code generation depends on is n, which is checked to ensure its integer value in advance. This yield only a unique disorder, as it should be.
I do not ask for a solution for my programming, I just want to find out the reasons for using goto to evaluate dynamic code or vice versa.
Edit: to clarify, the assignment involved writing a program using iterators, and the other using recursion, so the iterative version did not have to be effective.