Site icon TestingDocs.com

Dart return Statement

Overview

The Dart return statement is used to return a value.  A Dart function can have only one return statement in the function body. A function returns a value to the caller where it is invoked.

Dart return Statement

The general syntax of the Dart return statement is as follows:
return <return_value>;
Note that, the return statement is optional in the function.

Example

Let’s understand with an example.
int add(int a, int b) {
     var sum;
     sum = a + b ;
     return sum;
}

Returning a value from a function

For example, in the main() function, we can call the add() function to get the value.

var result;

result = add(45,27);

 

When a function is called, we have to pass some information as per the function prototype. The number of function parameters passed and data type while the function call must be matched with the number of parameters passed during function declaration.

The add() function has two parameters a and b.

Dart Tutorials

Dart tutorial on this website can be found at:

https://www.testingdocs.com/dart-tutorials-for-beginners/

More information on Dart:

https://dart.dev/

Exit mobile version