Why we define functions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
9th Feb 2019, 2:44 PM
Ashutosh Dash
Ashutosh Dash - avatar
4 Answers
+ 5
Your example definitely does not demonstrate the necessity of using functions, but imagine if you have 50 lines of code worth of calculations, which you have to use multiple times over the span of your entire program, it will be a better idea to write those 50 lines as a function and call the function every time you need to use it, instead of duplicating those 50 lines for each calculation.
9th Feb 2019, 3:01 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Reuseability. That way you'd only have to call the function instead of writing that code block over and over again.
9th Feb 2019, 2:53 PM
Jomari Pantorilla
Jomari Pantorilla - avatar
0
Jomari Pantorilla Hatsy Rei Thanks for answering but I'm still unable to understand it. Can you provide me a real life example to show the difference?
10th Feb 2019, 2:20 AM
Ashutosh Dash
Ashutosh Dash - avatar