Font size
WorksheetsFor Loop and Dry Run Revision Quiz
Total questions: 40
Worksheet time: 30mins
A (a) is used to repeat a block of code several times.
For loops are ________ ________ loops.
exit - controlled
entry - controlled
I don't know
All of the above
A for loop stops when the condition becomes
False
True
Which statement is executed first and only once ?
Conditional Expression
Update Statement
Initialization Statement
Code Block
A _____ ______ is a testing process where the
effects of a possible failure are
intentionally mitigated.
For Loop
Selections
While Loop
Dry Run
What is Dry Run also known as ?
Trace Table
Code Block
Table
Predict the Output:
<script>
for (var x = 1 ; x <= 10 ; x += 2)
{
document.write(x)
}
</script>
1 3 5 7 9
1 2 3 4 5 6 7 8 9
13579
246810
Predict the Output:
<script>
var x = 10
for (; x >= 1;)
{
document.write(x)
x --
}
</script>
109876543210
10987654321
1098654321
10876543210
Spot the Error:
<script> - i
for (var x = 1 , x <= 2 ; x ++) - ii
{
document.write(x) - iii
}
</script> - iv
i
ii
iii
iv
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>
i
ii
iii
iv
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
i
ii
iii
iv
Predict the Output:
<script>
var x = 10
for ( x >= 1 ; x -= 2)
{
document.write(x)
}
</script>
108642
10 8 6 4 2
No Output
9 7 5 3 1
Which cannot be omitted from the For Loop ?
;
{}
Update Statement
Initialization Statement
Synonyms of Loops
Iteration
Repetition
Looping
Selections
Dry Run is useful for _____ .
Seeing the Output of your code
Seeing how your code works in the memory of the computer
fun
I don't know
What are the three programming constructs ?
Iteration
Selections
Sequence
Dry Run
Spot the Error:
<script>
for (var x = 1 ; x <= 5 ; x ++) - i
{
document.write("Hi") - ii
} - iii
<script> - iv
i
ii
iii
iv
Spot the Error:
<script> - i
for (var x = 1 ; x <= 10 ; x += 3) - ii
{
document.writ("Hello") - iii
}
</script> - iv
i
ii
iii
iv
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>
149
150
151
100
Add the missing character to the code snippet:
<script>
for (var x = 1;x<=25;x++)
{
document.write(x)
}
<script>
(a)
Add the missing character to the code snippet:
<script>
for (var x = 1 x <= 10;x++)
{
document.write("Your name")
</script>
(a)
Remove the extra character from the code snippet:
<script>
for (var x = 1;x<<=5;x++)
{
document.write("Hi")
</script>
(a)
Semi colon after the for loop statement is mandatory.
True
False
Do for loops require a condition ?
Yes
No
Maybe
Can there be infinite loops ?
Yes
No
Not sure
Sam wrote the following code snippet. What is his mistake ?
for (var x = 1;x>=0;x++) - i
{ - ii
document.write(x) - iii
} - iv
i
ii
iii
iv
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>
x
name
var
script
Can nesting be done with for loops ?
Yes
No
Maybe
I don't know
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>
x ++
x --
x -= 1
x += 1
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>
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>
The code is correct
I don't know
""
{}
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 ?
Loops
Selections
Sequences
Nested Ifs
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>
""
,
;
{}
Fill in the blank: (Print numbers from 1 - 100 vetically)
<script>
var x = 1
for(;x<=100;x++)
{
(a)
}
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.
1
2
3
4
Add the missing statement to the following code snippet:
<script>
for (____;x<=25;x++)
{
document.write(x)
}
</script>
var x = 1
x += 1
x --
x *= 5
Complete the following code snippet:
<script>
____(var x = 1;x<=5;x++)
{
document.write(x + "<br>")
}
</script>
while
for in
for
I don't know
Which of the following are iterations ?
While Loops
For Loops
alert()
Document.write
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
iv
iii
ii
i
Which of the following is NOT part of the for loop syntax ?
Update Statement
Intialization Statement
doctype html
alert()
