Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

do-while vs do loop Quiz

Total questions: 5

Worksheet time: 50mins

Name
Class
Date
1.
What is the main difference between a while loop and a do-while loop?
a)
A: A while loop checks the condition before executing the loop body, while a do-while loop checks the condition after executing the loop body.
b)
B: A while loop can iterate an infinite number of times, while a do-while loop cannot.
c)
C: A while loop is used for definite iteration, while a do-while loop is used for indefinite iteration.
d)
D: There is no difference between them.
2.
How many times will the following loop execute? int x = 5; do { cout << x << endl; x--; } while (x > 0);
a)
A: 0 times
b)
B: 4 times
c)
C: 5 times
d)
D: Infinitely
3.
What is the output of the following code? int num = 0; do { cout << num << " "; num += 2; } while (num < 5);
a)
A: 0 2 4
b)
B: 0 2 4 6
c)
C: 2 4
d)
D: 2 4 6
4.
What is the output of the following code? int i = 0; while (i < 5) { cout << i << " "; i--; }
a)
A: 0 1 2 3 4
b)
B: 0 -1 -2 -3 -4 .......................never ends
c)
C: no output
d)
D: 4 3 2 1 0
5.
Which of the following is a valid syntax for a do-while loop in C++?
a)
A: do { // code } while (condition);
b)
B: do while (condition) { // code }
c)
C: do { // code } while condition;
d)
D: do while (condition); { // code }