+ 1

Why do we use functions in a programs?

what exactly they do, why they are used in a programs, are they important?

20th Mar 2017, 1:41 PM
Sourabh Sahil
Sourabh Sahil - avatar
2 Answers
+ 1
We use it to combine logic. Imagine that you are 4-6 years old. Your mother explains you how to buy milk and bread in the shop. Mission consists of some steps like "take this money", "be careful near the road", "be polite with seller" and etc. Now you are ** years old and you know how to do it, your mother can use this function, writed some years ago and give you only list with input parameters (products) and money. Now you can do it with you program, teach your program to do some operations once, wrap it like function and program will know how to do it in next time.
20th Mar 2017, 3:21 PM
Tony Loa
Tony  Loa - avatar
+ 1
Functions help you to avoid code repetition. Don't Repeat Yourself (DRY) is a basic rule in programming. Functions helps you to encapsule your tasks witch is a OOP concept. And also it help u to keep your code clean.
20th Mar 2017, 3:25 PM
Eranga
Eranga - avatar