-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFunctions.dart
66 lines (45 loc) · 1.17 KB
/
Functions.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
void main() {
printName();
print(greet("Aqsam"));
print(printValues()); // (12,Aqsam)
// or
final (age, name) = printValues();
print(age); // 12
print(name); // Aqsam
// 2nd Way to use Records n Functions
final values = Print_Data();
print(values.age);
print(values.String);
print(Print_Data());
int result = calculateFactorial(5);
print("Factorial: $result");
}
// Functions
// Function without a return value
void printName() {
print("Aqsam");
}
// Function with a return value
String greet(String name) {
return 'Hello, $name!';
}
// ******************* Records in Functions *******************
(int, String) printValues() {
return (12, "Aqsam");
}
// Another more reliable way to do that in order to avoid error or mistakes
({String String, int age}) Print_Data() {
return (age: 12, String: "Aqsam");
}
// Quick about Functions
// Instead of using {} braces you can use => in functions
//Recommended when when you have return single value
// Example #1 Factorial of a Number
int calculateFactorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * calculateFactorial(n - 1);
}
}
// Done with fumctions