A user-define function is a function that is created by the programmer for his/her custom need. It provides us the flexibility to reuse our code and divide them in small chunks. Let's discuss how we can create a user-define function in a dart.
First of all, remember, there are two main terminologies behind the use of function:
- function definition
- function call
function definition - It is a time when we define a function. At this time we define its name, work, parameters, and its return type, etc.
function call - It is a time when we need the function and we call it. Just remember before you call the function you need to define it. In short first define, the function then calls the function.
There are basically four parts of user-defined function:
- function name
- parameter
- return type
- function body
Function definition
It is a time when we define a function. At this time we define its name, work, parameters, and its return type, etc.
Syntax
function_name() {
//statements
}
Example
SayMyName () {
print("Jay Tillu");
}
Function calling
It is a time when we need the function and we call it. Just remember before you call the function you need to define it. In short first define, the function then calls the function.
Syntax
function_name ()
Example
SayMyName ()
Sample Program
SayMyName(){
print("Jay Tillu");
}
main(){
SayMyName();
}
Output
Jay Tillu
- Here first we define the function and then we call it from the main function.
This is the basics of function guys. In upcoming articles, we will discuss further in functions. Till then Keep Loving, Keep Coding. And I’ll surely catch you up in next article.
Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.
Learn more about Dart and Flutter
- List in Dart
- Abstract class and Abstract Methods in Dart
- Interface in Dart
- Constructors in Dart
- Arrow Function in Dart
- User Defined Function in Dart
- Functions in Dart
- Switch case in Dart
- Conditionals in Dart
- Operators in Dart
- Keywords in Dart
- Variables in Dart
- Data Types in Dart
Top comments (0)