Friday, March 29, 2024 07:21

Table of contents >> Functions > Execution workflow

Execution workflow

Whenever a method executes, it takes control over execution workflow of the program. However, if in the caller method we call yet another method, the execution is transferred to this new method, until it’s code is executed, and when that finishes, the execution control is returned to the first calling method.

This may not make much sense to you right now, or described in that fashion. So, to get it over with, basically, whenever we call a method or function in our program, the execution is immediately transferred to that piece of code, executes it, then comes back and resumes with the remaining code after the called method. Consider the following image:

execution workflow

So, we have our usual Main() method, in which we execute some code, among which we call a method which also contains some code. From the above image, we can see that the execution starts at the top of our Main() method, going downwards. As soon as it reaches the part where we call our method, the execution is immediately transferred to the part of code containing that method, where it will run all the code inside it. When that code is done executing, the execution is then re-transferred to our Main() method, where it continues with the codes that follow after the method call. If the called method would have contained another method call inside its body, the execution would have been transferred to that new location when it would have reached that method call, and returned to where it was, after the new method’s code would have been executed entirely.

The concepts explained in this lesson are also shown visually as part of the following video:

Tags: , , ,

Leave a Reply



Follow the white rabbit