-
Notifications
You must be signed in to change notification settings - Fork 0
/
#9-For_loop.dart
44 lines (31 loc) · 1.18 KB
/
#9-For_loop.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
void main() {
// <--------Loop Control Statement---------->
//For loop in dart\definite loop
//main loop structure
//intialize a varriable like var i = 1;
//Condition Check like i < 4
//Execute the main lopped code like some print statement
//increment varriable value by 1 in this statement i++
for (var i = 1; i <= 40; i++) {
if(i%2 == 1){
print(i);
}
}
//For ... in loop
//Mainly used for looping through an array
List planetList = ["Mars", "Venus", "Earth", "Mercury"]; //array of items
for (String planet in planetList){//it accuire
print(planet);
}
}
// How for loop Works internally
//flow of for loop
// initialize -> Condition Check -> Code Execute -> Increment/decremnt
/*
for(initializer; condition; increment/decrement){
Put maincode
}
loop1 int i = 1 -> condition=true -> code execute -> i++ then -> i = 2(continued)
loop2 i = 2 -> condition =true -> code execute -> i++ then -> i = 3(continued)
loop i = 3 -> condition = false -> loop terminated
*/