I have a method and inside of an if/then, I have it print the word "done" and then I call return. Problem is that is prints "done" about 100 times instead of exiting the method right away. It does eventually work, but why does it print "done" so many times first? It almost looks like a loop...
Originally posted by Max Simpson: doesn't calling 'return' cause the method to exit immediately, regardless of whether or not it is called from within a loop?
As others have said, there are cases where "return" doesn't return right away. But I doubt that's the problem here.
It sounds like you might be confused on what "return" returns from. It will cause the method to exit, but it's the method that the return is in. In other words, your function that prints "Done" is what the return will exit from. And when it exits, it winds up right back at the loop your function was called from. That method (the one with the loop) is not at all affected by the return that's in your "Done" method.