Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Loops in Dart Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which loop is used when the number of iterations is known in advance?

a)

While Loop

b)

Do-While Loop

c)

For Loop

d)

For-In Loop

2.

Which loop ensures that the code inside it is executed at least once before checking the condition?

a)

For Loop

b)

While Loop

c)

Do-While Loop

d)

ForEach Loop

3.

What will this code print? var list = [1, 2, 3]; for (var i in list) { print(i); }

a)

1, 2, 3

b)

1

c)

Error

d)

Infinite loop

4.

Which loop type is best suited to iterate over each item in an iterable like a List or Set?

a)

While Loop

b)

Do-While Loop

c)

For-In Loop

d)

For Loop

5.

What does the following code do? var i = 0; while (i < 5) { print(i); i++; }

a)

Prints 0 through 5

b)

Prints 0 through 4

c)

Prints an error

d)

Infinite loop

6.

Which loop would you use when you want to iterate over a list with a callback function for each element?

a)

For-In Loop

b)

While Loop

c)

Do-While Loop

d)

ForEach (on Iterable)

7.

Which of the following is true about a Do-While loop?

a)

The loop condition is checked before the first iteration.

b)

The loop runs infinitely.

c)

The loop executes at least once regardless of the condition.

d)

It is not possible to break the loop.

8.

What will the following code print? var i = 0; do { print(i); i++; } while (i < 3);

a)

0, 1, 2

b)

1, 2, 3

c)

Infinite loop

d)

Error

9.

What is the primary difference between a for loop and a while loop in Dart?

a)

A for loop executes an unknown number of times, while a while loop executes a known number of times.

b)

A for loop is used for iterating over collections, while a while loop is used for fixed iterations.

c)

A for loop checks the condition before each iteration, while a while loop does so after.

d)

There is no difference; they are functionally identical.

10.

Which of the following is NOT a loop type in Dart?

a)

For Loop

b)

For-In Loop

c)

Do-While Loop

d)

Repeat-Until Loop

11.

Which loop type is used when you don't know the number of iterations in advance, but you know the condition that needs to be true to stop the loop?

a)

For Loop

b)

While Loop

c)

Do-While Loop

d)

ForEach Loop

12.

What will the following code print? var i = 5; do { print(i); i--; } while (i > 0);

a)

5, 4, 3, 2, 1

b)

5, 4, 3, 2, 1, 0

c)

5, 4, 3, 2, 1

d)

Infinite loop

13.

What is the output of the following code? var list = ['apple', 'banana', 'cherry']; list.forEach((fruit) => print(fruit));

a)

apple, banana, cherry

b)

apple

c)

Error

d)

banana, cherry

14.

In the context of a for loop, what does the expression i++ do?

a)

Decreases the value of i by 1

b)

Increases the value of i by 1

c)

Resets the value of i to 0

d)

Multiplies i by 2

15.

What happens if the condition in a while loop is initially false?

a)

The loop will run infinitely.

b)

The loop will never execute.

c)

The loop will execute once.

d)

The loop will execute twice.

16.

Which loop type can be used to iterate through a map in Dart?

a)

For Loop

b)

For-In Loop

c)

ForEach Loop

d)

Do-While Loop

17.

What is the correct syntax to create an infinite while loop in Dart?

a)

while (true) {}

b)

while (1) {}

c)

while (true) {}

d)

for (;;)

18.

What will this for loop do? for (var i = 0; i < 3; i++) { print(i); }

a)

Print 3 times

b)

Print 0, 1, 2

c)

Print 0, 1

d)

Print 1, 2, 3

19.

How do you break out of a while loop early in Dart?

a)

stop;

b)

break;

c)

exit;

d)

end;

20.

Which of the following is NOT true about a forEach loop in Dart?

a)

It can be used to iterate over elements in a List.

b)

It takes a callback function as a parameter.

c)

It can be used to break out of the loop.

d)

It is mostly used for working with collections.