-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basics of dart.dart
82 lines (73 loc) · 1.83 KB
/
Basics of dart.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
//imports
//import 'location of the package';
import 'dart:io';
//Functions
// return type functionName (arguments){
// body}
void main() {
print("plese input a variable\n");
String inp;
inp = stdin.readLineSync();
print(inp);
int v = 0;
v = int.parse(stdin.readLineSync());
print("input: $v");
//LOOPS
int ctrl;
stdout.write("way 2\n");
ctrl = int.parse(stdin.readLineSync());
print("ctrl = $ctrl\n");
//for Loop
//for(control variable;bool;update){statements if bool is true}
for (int i = 0; i <= ctrl; i++) {
print('hello $i + 1');
}
//While Loop
//while(bool){
//statements if bool is true
//}
while (ctrl < 0) {
print(" while loop $ctrl");
ctrl++;
}
//do While
//do{}while(bool)
print("input ctrl $ctrl \n");
do {
print("do while $ctrl \n");
ctrl--;
} while (ctrl < 0);
//Error handling
//try{
//statements
//}catch(e){
//statements if error is encountered
//}
String s = stdin.readLineSync();
try {
ctrl = int.parse(s);
print("no error occurred, ctrl = $ctrl \n");
} catch (e) {
print("error : $e \n");
}
// dynamic type variables
// var variableName;
var dynVar;
dynVar = s;
var intType;
int v2 = 3;
intType = v2;
intType.runtimeType;
print("dynVar: ${dynVar.runtimeType} \n");
print("intType: ${intType.runtimeType} \n");
//NULL checking
//1. ?? {varible to be checked for NULL}??value to return if the variable is NULL
//2. ??= {varible to be checked for NULL}??value to be assigned to the variable
//3. ?. {variable to checked for null}?.{if varaible is not null the the propety of variable to call}??{value to return if varibale is NULL}
//3 will be discussed in later sessions
int testVar;
int t2 = testVar ?? 3;
print("t2 = $t2 \n");
testVar ??= 3;
print("testVar = $testVar \n");
}