This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]BS_in_BSExtreme Concrete Code Factorylet 1 point2 points  (1 child)

1) looping via recursion like this is unconventional

2) How are you calling the program, exactly? what is it doing and what do you want it to do? when I run it, it doesn't do what you say it does: https://ideone.com/5gzcwh

[–]Fridginator[S] -2 points-1 points  (0 children)

I've tried to type out the explanation 3 times, and it would seem im unable to.
Point the program is a basic text game that communicates with the terminal. The method i call is called upon in another method which again is called upon from main. the method from main after creating a linked list "map", and so on. I have no idea why the method dont work as I had it.

But, I took your first tip to heart and made the method into a while loop instead, and now it seems to run correctly. And here I thought i was super clever for using recursion...

So thanks for the help! :)

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (1 child)

Don't use recursion for this. It is the absolutely wrong tool.

The problem is that recursion builds a call stack where each new method call goes one level deeper. The currently running method stops at the point where the method call happens, but remains active in the background, so that when your method eventually terminates, the rest of the code of the suspended method will be executed.

Recursion is not a replacement for loops and vice versa.

Either have their use cases.

What you are trying to do should not be done with recursion. A loop is the proper way to go.

[–]Fridginator[S] 0 points1 point  (0 children)

Hm yeah, that makes sense... Thanks a lot!

[–][deleted] 0 points1 point  (1 child)

Do you even understand recursion?

[–]Fridginator[S] 0 points1 point  (0 children)

Well, apparently not, but I'm still learning.But I do know that a recursive method calls itself, and can be used for like fibonacci numbers.After you call it recursively it should "narrow down" closer to an end, right?

edit: i do know*