Hi fellas, could somebody answer how can i END a void recursion? I said END, not return to the previous call, I want something similar to "break" in loops but didn't find it in the web :/
Recursion is equivalent to iteration, so unless your recursive function is poorly designed, there's no reason why simply returning to the caller isn't a suitable way of stopping the recursion.
1 2 3 4 5 6
void f(int i){
if (!i)
return;
std::cout << i << std::endl;
f(i - 1);
}
No, OP wants to do something akin to breaking out of a deeply-nested loop.
It is an incorrect analogy. You cannot avoid passing back up through the call stack (unless you have tail-call recursion, which good C++ compilers will do for you if you design a TCO function).
[edit]
Well, there are a lot of ways to do it, actually, but like cire said, it is a non-problem.
Why do you think this matters?
Oh, I get it. The OP is asking to jump all the way through the stack back to the last call that wasn't named the same as the current one; all the way back to the first call to the function that is calling itself.
Yes, can't help but think this sounds like solving a problem that shouldn't (or doesn't really) exist.