Iteration
Actually the first three he used is the iteration. If you consider everything as one thing, other than recursion, as far as I know, there are only these two.
There are other ways to iterate that are not these commands, but the question indicates knowing this. Some paradigm may even use another way to call it, but it will still be an iteration. Or recursion. Depending on abstraction there are other possible commands in some languages, but it is only syntax, it is not a new concept.
And iterations end up becoming one branch. The other commands are abstractions (project patterns). Even the goto
ends up being an abstraction because the branch simple usually has less restrictions.
And it is good to make clear that the goto
can do repetitions, but there’s no guarantee it was used like this.
Recursion
There is a recursion in different ways than what you know, for example templates, or even said that it can occur with Generics (I’ve never seen it, but I believe it does), so it’s not just a function. Macros can also have something like this. But it is common that these recursions do not happen in the execution, it is solved at compile time.
Remembering that it is common in some languages that function recursion is transformed into iteration when compiled. Then in your code you will have recursion, but internally you will only have one iteration.
So what you see in your auto-repeat recursion code can disappear from the executable, either by unrolling for manual repetition or iteration transformation.
Handbook
These forms of repetition are mechanisms for automating a repetition. It is obviously possible to repeat manually, but I understand that this would be unwanted to what is in the question.
For example the application proliferate around is a manual form, not a repetition mechanism written in code.
Abstractions from previous concepts
Of course it can be creative if it can involve other abstractions (through library and/or rather complex code, one example is corotine, another is GUI, all will have one Event loop masked iterative), but will still use one of the above concepts.
If it involves resources external to the application it is also possible to repeat something, but in the background there will be an iteration or recursion, even if it is not in your code or application. We could call it signaling.
Will you consider these as different forms of repetition? Whatever, but they are just abstractions on top of the two already established concepts.
If it can involve something external to the language there are infinite ways to do and it would not fit to answer here, the list will always be incomplete.
Since the question does not involve a specific technology, I understand that it refers to the mathematical concept and what happens in its code and I could only identify these two.
Condition
Also I will say that without some trick that hides a condition, such as an external signaling that interferes in the flow for example, it is not possible to have automatic finite repetition without some form of condition.
Which is what I said in "Of course you can be creative if you can involve other abstractions or resources external to the application, but in the background there will be an iteration or recursion, even if it’s not in your code or application" and "Moreover I will say that without some trick that hides a condition, such as an external signaling that interferes in the flow for example, it is not possible to have automatic finite repetition without some form condition", it is not a mechanism of the code. I didn’t list since I understood that he was talking about code mechanisms. A scheduler does repetition.
– Maniero
The
setTimeout()
asks for the Runtime along with the operating system do the repeat, not the code. And in practice it’s still a recursion or iteration even if you don’t see it (so I don’t even know which one was used) "Depending on abstraction there are other possible commands in some languages, but it’s just syntax, not a new concept", which is the case of a coroutine. Since it does not have a specified language, to list all abstractions would have to see all possible abstractions already created in a language or library, nor would it consider those that the programmer could create.– Maniero
@Maniero It would be recursion if the function calls itself. In this case, it doesn’t call itself, it just asks for something else to call it. In addition, in a recursion, the result of the internal call is made available to the external one, which does not occur in a scheduling. Recursion also typically displays the call stacking of the same function on the runstack, which does not occur in scheduling. Therefore, this is not recursion, nor
for
, norwhile
and neithergoto
. It is true that there will be awhile
somewhere in the operating system or Runtime, but it is not being used directly.– Victor Stafusa
@Maniero And it is not very difficult to reduce the problem of defining what is or is not a new form of repetition to the halting problem. This implies that the number of ways to define repeating structures is essentially infinite. There will always be some newer and more sophisticated method of doing this, no matter how many previous methods have been invented.
– Victor Stafusa
You do not need to call yourself to be recursion, there is triangulated recursion. But that doesn’t matter, the fact is that if you don’t have a recursion there will be an iteration. Precisely in order not to enter into the infinite of the answer it is better to reduce to the abstract concepts, because if the question wanted a list of all possible abstract mechanisms to create, it would be too broad, perhaps the widest ever created on the site.
– Maniero
@Maniero The question is only asking that "in programming is there any other way to make loops?" - And certainly there is. It turns out that most of these forms are either niche things and very specific situations or they’re too crazy to make sense of being done by mere mortals. But that doesn’t make the answer turn negative.
– Victor Stafusa