Functions in Dart

in CCS3 days ago

Hello everyone!

image.png

Designed with Canva

Today I am here to share the concept of the functions in the dart programming language. Functions are very important in each programming language and similarly in the dart programming language.

Functions in Dart

A function is a block of code which performs a specific task. Sometimes we need to write the same code more than one time and in order to avoid this redundancy of the code we use functions. Functions allow us reusability of the code. We can pass arguments to the functions as well.

Some functions have no parameters and no return type or value. But on the other hand there is a type of functions which has a return type and parameter as well.


image.png

Here I have written a simple function without the return type. I have just used it to print a statement. After defining the function task I have called it in the main and it has completed the assigned task.


I will use a simple example to show you the usage of the functions. I will simply define the some basic arithmetic operations.


image.png

Here you can see that I have defined 4 functions. In each function a unique task is assigned. In the sum function I am adding two numbers. In the subtract function I am subtracting the two numbers. In the multiplication function I am multiplying both the numbers given by the user. Similarly in the division function I am dividing both the numbers.


image.png

In the main function I am getting two numbers from the user and passing these two the functions as parameter. Then I have printed all the functions.


image.png

Here after running the program it asked me to enter two numbers. I entered two numbers and it then called all the functions from the main by passing those two entered numbers. It printed all the exact results in the terminal.

In this way we can use functions in the dart programming language. There are a lot of properties of the functions which we will explore later and so far I have tried to explain the basics of functions.

Posted using SteemX

Sort:  

🎉 Congratulations!

Your post has been upvoted by the SteemX Team! 🚀

SteemX is a modern, user-friendly and powerful platform built for the Steem community.

🔗 Visit us: www.steemx.org

✅ Support our work — Vote for our witness: bountyking5

banner.jpg

 3 days ago 

🎉 Congratulations, @mohammadfaisal!

Your post Functions in Dart was rewarded by CCS Curation Trail

CCS Logo

“Home is where your heart is ❤️.”

👉 Join the CCS Curation Trail | Community Invitation

Vote Banner

Vote for visionaer3003 as witness