Are you ready?
1 questions to solve.
Instructions
- This quiz goes to full-screen once you press the Start button, or any Next button after exiting the quiz window.
- At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
A
True or false?
for
loop's header can be all blank like for (;;)
.True or false?
A for loop takes three statements in its header that are all optional. For more info please check out for loops in JavaScript.
The
continue
keyword does what inside a loop?The
continue
keyword skips the current iteration and continues on with the next iteration.while
iterates until the specified condition is false. True or false?When the condition given in the header of
while
fails i.e becomes false
only then does the loop terminate.A
for
loop's third statement has to always be with the ++
increment operator. True or false?There is no restriction into what we put in the third statement of
for
. It is evaluated on every iteration so we can have any legal statement there.If programmed incorrectly, a
True or false?
while
and a for
loop can run infinitely.True or false?
There is a chance of getting into infinite iterations by programming a loop incorrectly.
How to get the
while
loop executed at least once?Regardless of what condition is within
while
the do
block executes at least once.How to exit out of a loop?
The
break
keyword serves to exit out of a loop statement. In general it can also be used to exit out a block statement. See Javascript for loop and JavaScript switch for further details.How many times does the following loop run?
var i = 5;
for (; i < 5; i++) {
console.log(i);
}
i
is 5 hence i < 5
is false and thus the loop won't procede any further.Is the following code right or wrong?
var i = 5;
for (i < 5; i++) {
console.log(i);
}
Even if we don't specify the statements in the header of
for
loop, we still have to give the semi-colons indicating that the statements are left blank.