When should functions generally be created?



In general, when should functions be created in the code?


It is usually best to create a function if some process or calculations in code have to be repeated multiple times.

Creating a function will save you time from having to rewrite code lines over and over, by only having to write them once within the function. Furthermore, this can keep the code cleaner and more concise, which also will improve maintainability of the code, since we would only have to look at the code in the function one time when debugging.