-
Notifications
You must be signed in to change notification settings - Fork 1
/
if_statement.dart
80 lines (59 loc) · 1.69 KB
/
if_statement.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
void main() {
// ************************** Operators **************************
// > greater than
// < less than
// == Equality operator
// <= ,>= les than , greater than equal to
// && and operator
// || or operator
// ! , != not , not is equal to
// ************************** if Statements **************************
// ******** Simple :
// int age = 21;
// if (age < 18) {
// print("Child Spotted ");
// } else {
// print("You'r an Adult ");
// }
// ******** else if
// int age1 = 21;
// if (age1 < 18) {
// print("Child Spotted ");
// } else if (age1 > 18) {
// print("You can join the party");
// } else {
// print("You can't join the party ");
// }
// ******** 1 more example else if
// int age3 = 42;
// if (age3 > 0 && age3 <= 18) {
// print("You'r a kid ! \nYou cant join the party");
// } else if (age3 > 18 && age3 < 40) {
// print("yes , You can join the Party !");
// } else {
// print("You'r too young , You can't join the party : ");
// }
// ****************** Ternary ********************
// String somevalue = "Hello";
// String value = somevalue.startsWith("H") ? "World" : "Empty";
// print(value);
// ************************** Switch Statements **************************
String value = "Hello";
int num = 10;
// Ex 1 :
switch (value) {
case "Hello":
print("Hello World");
// break statement is not necessary in dart until dart 3.0
default:
print("Empty");
}
// Ex 2 :
// Multiple conditions for variable(value) using when
switch (value) {
case "Hello" when num == 10:
print("All Conditions are ok");
default:
print("Not All Conditions are Ok");
}
}