Professional Documents
Culture Documents
Day3-1-Loops - 3 Hours - 080801
Day3-1-Loops - 3 Hours - 080801
Day3-1-Loops - 3 hours
Dart Loop is used to run a block of code repetitively for a given number of
times or until matches the specified condition. Loops are essential tools
for any programming language. It is used to iterate the Dart iterable such
as list, map, etc. and perform operations for multiple times. A loop can
have two parts - a body of the loop and control statements. The main
objective of the loop is to run the code multiple times. Dart supports the
following type of loops.
1 of 14 10/11/23, 12:22 AM
Day3-1-Loops - 3 hours https://devnation.notion.site/Day3-1-Loops-3-hours-40b1a9d43a5b465...
The loop iteration starts from the initial value. It executes only once.
The condition is a test expression and it is checked after each iteration.
The for loop will execute until false returned by the given condition.
The incr/decr is the counter to increase or decrease the value.
Let's understand the following example.
Example -
Output:
1
2
3
4
5
6
7
8
9
10
Copy the above code and paste it into DartPad below to practice:
2 of 14 10/11/23, 12:22 AM
Day3-1-Loops - 3 hours https://devnation.notion.site/Day3-1-Loops-3-hours-40b1a9d43a5b465...
Example :
Output:
10
20
3 of 14 10/11/23, 12:22 AM
Day3-1-Loops - 3 hours https://devnation.notion.site/Day3-1-Loops-3-hours-40b1a9d43a5b465...
30
40
50
We need to declare the iterator variable to get the element from the
iterator.
Copy the above code and paste it into DartPad below to practice:
4 of 14 10/11/23, 12:22 AM
Day3-1-Loops - 3 hours https://devnation.notion.site/Day3-1-Loops-3-hours-40b1a9d43a5b465...
Output:
1
2
3
4
5
6
7
8
9
Copy the above code and paste it into DartPad below to practice:
5 of 14 10/11/23, 12:22 AM
Day3-1-Loops - 3 hours https://devnation.notion.site/Day3-1-Loops-3-hours-40b1a9d43a5b465...
Example -
Output:
The value is: 1
The value is: 2
The value is: 3
The value is: 4
The value is: 5
The value is: 6
The value is: 7
The value is: 8
The value is: 9
6 of 14 10/11/23, 12:22 AM
Day3-1-Loops - 3 hours https://devnation.notion.site/Day3-1-Loops-3-hours-40b1a9d43a5b465...
Copy the above code and paste it into DartPad below to practice:
• Analyze the problem and observe whether you need a pre-test loop
or a post-test loop. A pre-test loop is where the condition is tested
before entering the loop. In the post-test loop, the condition is tested
after entering the loop.
7 of 14 10/11/23, 12:22 AM