forked from MadhushaPrasad/studious-couscous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
84 lines (60 loc) · 1.66 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import 'dart:core';
// Importing core libraries
import 'dart:math';
// Importing libraries from external packages
//import 'package:test/test.dart';
// Importing files
import 'others/my_Other_file.dart';
main() {
//main function
print("Hello World");
//variables
var name = "Madhusha"; //string
var year = 1234; //number
var salary = 10000.50; //floating point
var planets = ['Jupiter', 'Saturn', 'Uranus', 'Neptune']; //Array
var image = {
//json object
'tags': ['saturn'],
'url': '//path/to/saturn.jpg'
};
//print(name); //use to print something on console
//print(year);
//print(salary);
//print(image['url']);
//control flow Statements
if (year >= 2001) {
//if statement
print('21st century');
} else if (year >= 1901) {
print('20th century');
}
for (var object in planets) {
//for loop as a for in
print(object);
}
for (int month = 1; month <= 12; month++) {
//same as other language's for loop
print(month);
}
while (year < 2016) {
//while loop as it is other languages
year += 1;
}
//function implimentation and call
int fibonacci(int n) {
if (n == 0 || n == 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
var result = fibonacci(0); //function calling
//print(result);
planets
.where((name) => name.contains('turn'))
.forEach(print); //anonymous functions
/* Comments */
// This is a normal, one-line comment.
/// This is a documentation comment, used to document libraries,
/// classes, and their members. Tools like IDEs and dartdoc treat
/// doc comments specially.
/* Comments like these are also supported. */
}