Calling a method inside another method

While working on the PrimeDirective project, I noticed that the method isPrime was not called on the object pd. Is that because isPrime is nested inside another method, called onlyPrimes, and onlyPrimes is called on pd!?

Yes! It’s quite possible to have methods and functions within others.
You can also have a function call itself (recursion). When doing this it’s important to make sure that the function has a way to finish.

1 Like