Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

For and While Loops

Total questions: 28

Worksheet time: 2hrs 20mins

Name
Class
Date
1.

Repeating a task multiple times in programming is known as ?

a)

Iterators

b)

Scope

c)

Looping

2.

When there is an error in the logic of the loop because the stopping condition is never reached.

a)

Arrays

b)

Infinite Loop

c)

Looping

3.

for loops allow us to repeat a block of code a known amount of times.

a)

True

b)

False

4.

Each item inside of an array is at a numbered position, starting at ?

a)

1

b)

0

5.

_____ loops let us loop a block of code a known amount of times.

a)

while

b)

for

6.

As long as the condition evaluates to _____, the block of code will loops.

a)

true

b)

false

7.

_____ loops let us loop a block of code an unknown amount of times.

a)

for

b)

while

8.

what is a for loop?

a)

loops through a number of block of code one time

b)

loops through a block of code a number of times

c)

loops through a block of code one time

d)

many loops through a block of code a number of times

9.

The number is 0

The number is 1

The number is 2

The number is 3

The number is 4

which is the correct code?

a)

for (i = 0; i < 5 i++)

b)

FOR (i = 0; i < 5; i++)

c)

for (i = 0; i < 4; i++)

d)

for (i = 0; i < 5; i++)

10.

what is a while loop?

a)

loops through a block of code as long as a specified condition is false

b)

loops through a block of code as long as a specified condition is true or false

c)

loops through a block of code as long as a specified condition is true

d)

loops through a number block of code as long as a specified condition is true

11.

What is the final sum after this loop executes

a)

sum = 5

b)

sum = 10

c)

sum = 15

12.

Which of these is a loop?

a)

if(x<10)

b)

for( var x=0; x<10; x++)

c)

var x=10;

d)

loop(x,10;10)

13.

What is the symbol used for the INCREMENT operator in JS?

a)

+

b)

++

c)

=

d)

==

14.
Arithmetic Operators
What is ++ ?
a)
Modulo
b)
increment
c)
Decrement
d)
Addition
15.

Repeat something 10 times

a)

repeat 10

b)

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

c)

repeat { } until 10;

d)

while (i = 10)

16.

Loops use these to eventually exit the loop

a)

Numbers and letters

b)

conditions with logic and comparison

c)

class or ID

d)

input from the keyboard

17.

This loop starts counting from 10

a)

for(var i=10; i>0; i--)

b)

var i = 10;

c)

count=10;

d)

for(var i=0; i>0; i--)

18.

adds one to variable x in a loop

a)

increment (x)

b)

x++;

c)

x=x;

d)

y+1;

19.
A condition is __________.
a)
any expression that evaluates to True or False
b)
a built-in function that assigns a Boolean value to a variable
c)
a formula that is executed for a result
d)
an operand that indicates both conditions are True or False
20.

Repeat code a fixed number of times.

a)

While Loop

b)

Loop

c)

If Statement

d)

For Loop

21.

Why are the curly braces needed for loops?

a)

To tell the program where the loop begins and ends

b)

To tell the program when to stop looping

c)

To declare a new variable

22.
Why do we use loops? 
a)
It is easy to type
b)
It saves time
c)
To repeat a block of code without having to retype
d)
It is faster to create
23.

Why are the curly braces needed for loops?

a)

To tell the program where the loop begins and ends

b)

To tell the program when to stop looping

c)

To declare a new variable

24.

what is the __ missing in this loop


for ( ____ ; x<10; x++);

a)

set a start value for x

b)

exit the loop when x is 11

c)

start x at zero

d)

the loop is not missing code

25.

Repeat something 10 times

a)

repeat 10

b)

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

c)

repeat { } until 10;

d)

while (i = 10)

26.

The proper way to code a loop condition

a)

Starts TRUE and later changes to FALSE

b)

Loop

c)

Starts FALSE and stays FALSE

d)

Starts FALSE and turns TRUE to exit the loop

27.

Which of the following statements is/are correct?

a)

Statement 1 is executed (one time) before the execution of the code block.

b)

Statement 2 defines the condition for executing the code block.

c)

Statement 3 is executed (every time) after the code block has been executed.

28.

In order to create a loop that runs from 0 to 9, what would you have to fill into the empty box?

(a)