Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thanks, but one little question. After the if the code executes the forloop, but isn't iat that moment 1, how does it become 2? Commented Jan 24, 2017 at 14:57
  • @YoussefSakuragi By returning to the invocation of the method from which it was called, where i is 2. A fundamental concept in recursion is that the multiple calls are stacked up until you get back to them. Commented Jan 24, 2017 at 15:02
  • 2
    the i-1 does not change the value of i, instead it creates a new value, which is passed to the next invocation. But once the method returns, the value of the original i is valid again, Commented Jan 24, 2017 at 15:04
  • 1
    @YoussefSakuragi Look up "call by value" and "call by reference", then learn how Java does things. The i-1 is evaluated and that value is passed to the method call as argument. Commented Jan 24, 2017 at 15:11