Search Header Logo
Week 3 - Loops (DCS1101)

Week 3 - Loops (DCS1101)

Assessment

Presentation

Computers

University

Practice Problem

Medium

Created by

Yasmin Basiran

Used 3+ times

FREE Resource

26 Slides • 9 Questions

1

media

2

media

3

media

4

Open Ended

If a game gives you 3 lives, what should happen when lives reach 0?

5

Open Ended

Can a program make decisions forever?

6

media

7

media

8

media

9

media

10

media

11

media

12

media

13

media

14

media

15

media

16

media

17

media

18

media

19

media

20

media

21

media

22

media

23

Multiple Choice

Which loop is most likely to cause an infinite loop?

1

for

2

while

3

do-while

4

Any loop without update

24

Multiple Choice

What is the output?

int x = 1;

while (x <= 3) {

cout << x << " ";

x++;

}

1
1 2 3
2
0 1 2
3
2 3 4
4
1 2

25

Multiple Choice

Which loop is better when number of repetitions is unknown?

1
for loop
2
while loop
3
do-while loop
4
foreach loop

26

media

27

media

28

media

29

media

30

media

31

Draw

Draw a flowchart for a loop that prints numbers 1 to 5.

32

Open Ended

Write a countdown from 5 to 1.

33

Multiple Choice

Find the error of this code
int x = 1;

while (x <= 5) {

cout << x;

}

1
The code will result in an infinite loop.
2
The loop will execute only once.
3
The variable x is not initialized properly.
4
The code will compile but not run.

34

Open Ended

What is the error for this loop?

for (int i = 1; i <= 5; i--) {

cout << i;

}

35

media
media

Show answer

Auto Play

Slide 1 / 35

SLIDE