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++;  
    }  
  • (A) The continue keyword skips the next iteration
  • (B) The continue keyword restarts the loop
  • (C) It is used for skipping the rest of the statements in that particular iteration
  • (D) The "continue" keyword breaks out of the loop
πŸ’¬ Discuss
βœ… 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

Explanation by: Mr. Dubey

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
228
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Indresh Gehalot
Publisher
πŸ“ˆ
95%
Success Rate