wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Arduino Loop

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

2.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

3.

Which of the following is the correct format of a "for" loop?

a)

for(int i = 0; i < 10; i++);

b)

for[int i = 0; i < 10; i++];

c)

for(int i = 0; i < 10; i++)

d)

for[int i = 0; i < 10; i++]

4.

What type of a loop is a for loop?

a)

Fixed Length

b)

Variable Length

c)

Infinite Length

d)

Imaginary Length

5.

How many times will the shown for loop execute?

a)

0

b)

9

c)

10

d)

11

6.

How many times will the shown for loop execute>

a)

0

b)

100

c)

20

d)

50

7.

What are the three parts of a for loop?

a)

initialize; test; increment

b)

test; initialize; increment

c)

increment; test; initialize

d)

Larry; Mo; Curly

8.

What output is produced by the following segment of code:


for(int i = 0; i < 10; i++)

cout << i << " ";

a)

0 1 2 3 4 5 6 7 8 9 10

b)

0 1 2 3 4 5 6 7 8 9

c)

1 2 3 4 5 6 7 8 9 10

d)

1 2 3 4 5 6 7 8 9

e)

Infinite Loop

9.

What output is produced by the following segment of code:


for(int i = 0; i <= 10; i++)

cout << i << " ";

a)

0 1 2 3 4 5 6 7 8 9 10

b)

0 1 2 3 4 5 6 7 8 9

c)

1 2 3 4 5 6 7 8 9 10

d)

1 2 3 4 5 6 7 8 9

e)

Infinite Loop

10.

What output is produced by the following segment of code:


for(int i = 1; i <= 10; i++)

cout << i << " ";

a)

0 1 2 3 4 5 6 7 8 9 10

b)

0 1 2 3 4 5 6 7 8 9

c)

1 2 3 4 5 6 7 8 9 10

d)

1 2 3 4 5 6 7 8 9

e)

Infinite Loop

11.

What output is produced by the following segment of code:


for(int fun = 20; fun > 1; fun -=3)

cout << fun << " ";

a)

20 17 14 11 8 5 2 -1

b)

20 17 14 11 8 5 2

c)

17 14 11 8 5 2 -1

d)

20 17 14 11 8 5

e)

Infinite Loop

12.

What output is produced by the following segment of code:


int start = 5;

int end = 20;

for(; start <= end; start +=2)

cout << start << " ";

a)

5 7 9 11 13 15 17 19 21

b)

7 9 11 13 15 17 19 20

c)

7 9 11 13 15 17 19 21

d)

5 7 9 11 13 15 17 19

e)

Infinite Loop

13.

What output is produced by the following segment of code:


for (int dmc = 8; dmc >= 0; dmc-=4)

cout << dmc << " ";

a)

8 4 0

b)

8 4

c)

8

d)

No Output

e)

Infinite Loop

14.

What output is produced by the following segment of code:


for (int dmc = 8; dmc >= 8; dmc-=4)

cout << dmc << " ";

a)

8 4 0

b)

8 4

c)

8

d)

No Output

e)

Infinite Loop

15.

What output is produced by the following segment of code:


for (int dmc = 8; dmc >= 10; dmc-=4)

cout << * << " ";

a)

* * *

b)

* *

c)

*

d)

No Output

e)

Infinite Loop

16.

What output is produced by the following segment of code:


for (int x = 5; x > 0; x--);

cout << * << " ";

a)

* * * * *

b)

* * * * * *

c)

*

d)

No Output

e)

Infinite Loop

17.

What does the following code print?

for( int w=3; w<=12; w++ )

cout << w << " ";

a)

5 6 7 8 9

b)

4 5 6 7 8 9 10 11 12

c)

3 5 7 9 11

d)

3 4 5 6 7 8 9 10 11 12

18.

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

19.

This code prints all tenths from 0 to 100.

int numbers = 0;

while( numbers <= 100 ){

cout << numbers << " ";

numbers+=10;

}

a)

True

b)

False

20.

Which of the following 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 )