wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

For Loop and Dry Run Revision Quiz

Total questions: 40

Worksheet time: 30mins

Name
Class
Date
1.

A (a)   is used to repeat a block of code several times.

2.

For loops are ________ ________ loops.

a)

exit - controlled

b)

entry - controlled

c)

I don't know

d)

All of the above

3.

A for loop stops when the condition becomes

a)

False

b)

True

4.

Which statement is executed first and only once ?

a)

Conditional Expression

b)

Update Statement

c)

Initialization Statement

d)

Code Block

5.

A _____ ______ is a testing process where the

effects of a possible failure are

intentionally mitigated.

a)

For Loop

b)

Selections

c)

While Loop

d)

Dry Run

6.

What is Dry Run also known as ?

a)

Trace Table

b)

Code Block

c)

Table

7.

Predict the Output:


<script>

for (var x = 1 ; x <= 10 ; x += 2)

{

document.write(x)

}

</script>

a)

1 3 5 7 9

b)

1 2 3 4 5 6 7 8 9

c)

13579

d)

246810

8.

Predict the Output:


<script>

var x = 10

for (; x >= 1;)

{

document.write(x)

x --

}

</script>

a)

109876543210

b)

10987654321

c)

1098654321

d)

10876543210

9.

Spot the Error:


<script> - i

for (var x = 1 , x <= 2 ; x ++) - ii

{

document.write(x) - iii

}

</script> - iv

a)

i

b)

ii

c)

iii

d)

iv

10.

Spot the Error:


<script>

var x = 1

var y = 1

for (; x <= 5 ;); - i

{

document.write(x) - ii

}

for (; y <= 10 ;) - iii

{

document.write(y) - iv

}

</script>

a)

i

b)

ii

c)

iii

d)

iv

11.

Spot the Error:


<script>

var x = 1

for (; x <= 10 ;) - i

{

document.write(x) - ii

x ++

- iii

</script> - iv


Note: Each number refers to the its line

a)

i

b)

ii

c)

iii

d)

iv

12.

Predict the Output:


<script>

var x = 10

for ( x >= 1 ; x -= 2)

{

document.write(x)

}

</script>

a)

108642

b)

10 8 6 4 2

c)

No Output

d)

9 7 5 3 1

13.

Which cannot be omitted from the For Loop ?

a)

;

b)

{}

c)

Update Statement

d)

Initialization Statement

14.

Synonyms of Loops

a)

Iteration

b)

Repetition

c)

Looping

d)

Selections

15.

Dry Run is useful for _____ .

a)

Seeing the Output of your code

b)

Seeing how your code works in the memory of the computer

c)

fun

d)

I don't know

16.

What are the three programming constructs ?

a)

Iteration

b)

Selections

c)

Sequence

d)

Dry Run

17.

Spot the Error:


<script>

for (var x = 1 ; x <= 5 ; x ++) - i

{

document.write("Hi") - ii

} - iii

<script> - iv

a)

i

b)

ii

c)

iii

d)

iv

18.

Spot the Error:


<script> - i

for (var x = 1 ; x <= 10 ; x += 3) - ii

{

document.writ("Hello") - iii

}

</script> - iv

a)

i

b)

ii

c)

iii

d)

iv

19.

Predict the Output:


<script>

var sum1 = 0

var sum2 = 0

for (var x = 1 ; x <= 5 ; x ++)

{

sum1 += x

}

for (var y = 20 ; y <= 25 ; y ++)

{

sum2 += y

}

document.write(sum1 + sum2)

</script>

a)

149

b)

150

c)

151

d)

100

20.

Add the missing character to the code snippet:


<script>

for (var x = 1;x<=25;x++)

{

document.write(x)

}

<script>

(a)  

21.

Add the missing character to the code snippet:


<script>

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

{

document.write("Your name")

</script>

(a)  

22.

Remove the extra character from the code snippet:


<script>

for (var x = 1;x<<=5;x++)

{

document.write("Hi")

</script>

(a)  

23.

Semi colon after the for loop statement is mandatory.

a)

True

b)

False

24.

Do for loops require a condition ?

a)

Yes

b)

No

c)

Maybe

25.

Can there be infinite loops ?

a)

Yes

b)

No

c)

Not sure

26.

Sam wrote the following code snippet. What is his mistake ?


for (var x = 1;x>=0;x++) - i

{ - ii

document.write(x) - iii

} - iv

a)

i

b)

ii

c)

iii

d)

iv

27.

What is the loop control variable in this code snippet ?


<script>

var name = "Sam"

for (var x = 1;x<=5;x++)

{

document.write(name)

}

</script>

a)

x

b)

name

c)

var

d)

script

28.

Can nesting be done with for loops ?

a)

Yes

b)

No

c)

Maybe

d)

I don't know

29.

Jake wants to display the numbers from 1 to 10 in reverse order. What should he add to correct his code snippet ?


<script>

var x = 10

for (;x>=1;____)

{

document.write(x)

}

</script>

a)

x ++

b)

x --

c)

x -= 1

d)

x += 1

30.

Riya wants to display the first 25 natural numbers vertically. What should she add to correct her code snippet ?


<script>

for (var x = 1; (a)   ;x ++)

{

document.write(x + "<br>")

}

</script>

31.

James wants to display numbers from 50 to 75 horizontally. What should he remove from his code snippet to make it work ?


<script>

for (var x = 50;x<=75;x++)

{

document.write("x")

}

</script>

a)

The code is correct

b)

I don't know

c)

""

d)

{}

32.

Jack wants to print his name 5 times. He writes document.write("Jack") 5 times. What alternative could he use to give the same output ?

a)

Loops

b)

Selections

c)

Sequences

d)

Nested Ifs

33.

Jamie does not understand why her code is not working. What should she remove in order to fix the code ?


<script>

var x = 1

for (,x<=5;x++)

{

document.write(x)

}

</script>

a)

""

b)

,

c)

;

d)

{}

34.

Fill in the blank: (Print numbers from 1 - 100 vetically)


<script>

var x = 1

for(;x<=100;x++)

{

(a)  

}

35.

How many for loops will be required to solve the following question ?


Write a program using for loops in Java script to display the sum of the numbers from 1 - 50 and the sum of numbers from 60 - 100 and the sum of numbers from 110 to 150.

a)

1

b)

2

c)

3

d)

4

36.

Add the missing statement to the following code snippet:


<script>

for (____;x<=25;x++)

{

document.write(x)

}

</script>

a)

var x = 1

b)

x += 1

c)

x --

d)

x *= 5

37.

Complete the following code snippet:


<script>

____(var x = 1;x<=5;x++)

{

document.write(x + "<br>")

}

</script>

a)

while

b)

for in

c)

for

d)

I don't know

38.

Which of the following are iterations ?

a)

While Loops

b)

For Loops

c)

alert()

d)

Document.write

39.

Sammy needs help in the following code. Can you find her mistake ?


<script> - i

for(var x = 1;x<=100;x++); - ii

{

document.write(x) - iii

}

</script> - iv

a)

iv

b)

iii

c)

ii

d)

i

40.

Which of the following is NOT part of the for loop syntax ?

a)

Update Statement

b)

Intialization Statement

c)

doctype html

d)

alert()