DEV Community

Cover image for User Define function in Dart
Jay Tillu😎
Jay Tillu😎

Posted on • Updated on

User Define function in Dart

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:

  1. function definition
  2. 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:

  1. function name
  2. parameter
  3. return type
  4. 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
}
Enter fullscreen mode Exit fullscreen mode

Example

SayMyName () {
  print("Jay Tillu");
}
Enter fullscreen mode Exit fullscreen mode

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 ()
Enter fullscreen mode Exit fullscreen mode

Example

SayMyName ()
Enter fullscreen mode Exit fullscreen mode

Sample Program

SayMyName(){
  print("Jay Tillu");
}
main(){
  SayMyName();
}

Output
Jay Tillu
Enter fullscreen mode Exit fullscreen mode
  • 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.

For More Information Please Visit Following Links

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

Top comments (0)