Q. What is the role of the "continue" keyword in the following piece of JavaScript code?
Code: while (x !=0)
{
if(x ==1)
continue;
else
x++;
}
β
Correct Answer: (C)
It is used for skipping the rest of the statements in that particular iteration
Explanation:
Let's solve it carefully.
In this JavaScript code:
while (x != 0)
{
if (x == 1)
continue;
else
x++;
}
- When continue is encountered, it immediately skips the rest of the statements inside the loop for that particular iteration and jumps to the next iteration.
- It does not break the loop (unlike break).
- It does not restart the loop from the beginning; it just moves to the next cycle.
Thus:
The "continue" keyword is used for skipping the rest of the statements in that particular iteration.
Final Answer:
(C) It is used for skipping the rest of the statements in that particular iteration