We've seen that lines of code execute sequentially in the order they're written, but bringing methods into the picture introduces a unique situation. Calling a method tells the program to take a detour into the method instructions, run them one by one, and then resume sequential execution where the method was called.
Take a look at the following screenshot and see whether you can figure out in what order the debug logs will be printed out to the console:
These are the steps that occur:
- Choose a character prints out first because it's the first line of code.
- When GenerateCharacter() is called, the program jumps to line 23, prints out Character: Spike, then resumes execution at line 17.
- A fine choice prints out last, after all the lines in GenerateCharacter() have finished running:
Now, methods in themselves wouldn't be very useful beyond simple examples like these if we couldn't add parameter...