# Recursion, with using Lists to store data

mandlar suurla
Ranch Hand
Posts: 67
I am struggling with this problem for long time and i haven't found any simple solutions.

As you can see i have made simple list to store numbers from 0 to 4, but the problem it gets the stackOverFlowError.
The result should be list.get(0) = 0 ... and list.get(3) = 4

Stephan van Hulst
Bartender
Posts: 6113
73
• 1
Hey there! Can you explain in your own words what the difference is between:

++counter;
and
counter++?

If you don't know the difference, look up what the difference is between prefix increment and postfix increment.

Take note that the correct words are "recursion" and "recursive", not "recrusion" and "recrusive".

mandlar suurla
Ranch Hand
Posts: 67
Stephan van Hulst wrote:Hey there! Can you explain in your own words what the difference is between:

++counter;
and
counter++?

If you don't know the difference, look up what the difference is between prefix increment and postfix increment.

Take note that the correct words are "recursion" and "recursive", not "recrusion" and "recrusive".

prefix increment, the statement value is increased first before use, but postfix increment takes value and then increases.

example
counter = 0;

if (++counter) -- the counter is increased first and then the boolean check if (1)

if (counter++) -- counter is increased after use in statement if (0) and then make +1

Am I right ? But the problem still lies in recursion.

Stephan van Hulst
Bartender
Posts: 6113
73

Actually no, there are no checks. The prefix operator first increases the variable, and then returns the value. The postfix operator increases the variable, but returns the value it was before the increment.
How could this affect your recursion?