wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Loops

Total questions: 19

Worksheet time: 11mins

Name
Class
Date
1.

Make this code loop three times:


int tries= 0;

while(_________ ) {

cin>> “Looping!”;

tries++;

}

a)

tries < 3

b)

answer == 3

c)

tries > 0

d)

tries < 0

2.

Fill in the blank with the right symbol to make this code print Tacos 4 times


int tacos = 4;

while(tacos (a)   0) {

cout<<“Tacos”<<endl;

tacos - - ;

}

3.

Fill in the blank to make this code print Go Heat!

3 times


int loop = 0;

while(__________) {

cout<<“Go Heat”<<endl;

loop++;

}

a)

loop < 3

b)

answer == 3

c)

loop = 0

d)

loop == 3

4.

Fill in the blank with the right symbol to make this code print I'm a coder 3 times


int loop = 0;

while(loop (a)   3) {

cout<<“I'm a coder”<<endl;

loop++ ;

}

5.

Select all of the statements properly increments an int variable by one?

a)

variable++;

b)

variable += 1;

c)

variable + 1;

d)

variable = variable * variable;

6.

Select all of the statements properly decrements an int variable by one?

a)

variable = variable - 1;

b)

variable -= 1;

c)

variable - -;

d)

variable - variable;

e)

variable - 1;

7.

True or False. This code prints all tenths from 0 to 100


int numbers = 0;

while(numbers <=100) {

cout<<numbers<<" ";

numbers+=10;

}

a)

True

b)

False

8.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to

9.

Which of the following is NOT a logical operator in C++ language?

a)

&

b)

&&

c)

||

d)

!

10.

Which of the following is NOT a comparison operator in C++ language?

a)

>

b)

<=

c)

=

d)

==

11.
How many times will it repeat displaying the text(I deserve a good education) on the screen?
a)
4
b)
5
c)
6
d)
infinite
12.

The cout statement in the following program segment will display 5:


int x = 5;

cout << x++;

a)

True

b)

False

13.

Which of the following while-clauses tells the computer to exit the loop when the value in the age variable is less than the number 0?

a)

while (age < 0)

b)

while age >= 0;

c)

while (age !> 0)

d)

while (age >= 0)

14.

Values that are used to end loops are referred to ______

values.

a)

closing

b)

ending

c)

sentinel

d)

stop

15.

What's wrong?

while( (i < 10) && (i > 24))

a)

the logical operator && cannot be used in a test condition

b)

the while loop is an exit-condition loop

c)

the test condition is always false

d)

the test condition is always true

16.

The statement i*=3 is equivalent to ____.

a)

i = 3*

b)

i = 3

c)

*i = 3

d)

i = i * 3

17.

The expression c = i++ causes ______.

a)

the value of i assigned to c and then i incremented by 1

b)

i to be incremented by 1 and then the value of i assigned to c

c)

value of i assigned to c

d)

i to be incremented by 1

18.

How many times will the computer process the statement in the following code?

int x = 0;

while (x > 3)

{

cout << x << endl;

x = x + 1;

}

a)

0

b)

2

c)

3

d)

4

19.

What will be displayed when the following code is executed?

int number = 6;

while (number > 0)

{ number -= 3;

cout << number << " "; }

a)

6 3 0

b)

6 3

c)

3 0

d)

0 -3