Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
- Dart Programming
Practical Paper
Industrial Training
Dart Programming - Functions
Functions are the building blocks of readable, maintainable, and reusable code. A function is a set of statements to perform a specific task. Functions organize the program into logical blocks of code. Once defined, functions may be called to access code. This makes the code reusable. Moreover, functions make it easy to read and maintain the program’s code.
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
Sr.No | Function & Description |
1 | Defining a Function |
2 | Calling a Function |
3 | Returning Functions |
4 | Parameterized Function |
Optional Parameters
Optional parameters can be used when arguments need not be compulsorily passed for a function’s execution. A parameter can be marked optional by appending a question mark to its name. The optional parameter should be set as the last argument in a function.
We have three types of optional parameters in Dart −
Sr.No | Parameter & Description |
1 | Optional Positional Parameter |
2 | Optional named parameter |
3 | Optional Parameters with Default Values |
Recursive Dart Functions
Recursion is a technique for iterating over an operation by having a function call to itself repeatedly until it arrives at a result. Recursion is best applied when you need to call the same function repeatedly with different parameters from within a loop.
Example
void main() { print(factorial(6)); } factorial(number) { if (number <= 0) { // termination case return 1; } else { return (number * factorial(number - 1)); // function invokes itself } }
It should produce the following output −
720
Lambda Functions
Lambda functions are a concise mechanism to represent functions. These functions are also called as Arrow functions.
Syntax
[return_type]function_name(parameters)=>expression;
Example
void main() { printMsg(); print(test()); } printMsg()=> print("hello"); int test()=>123; // returning function
It should produce the following output −
hello 123