Challenge - 5 Problems
Continue Statement Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of loop with continue
What is the output of the following code?
Javascript
let result = ''; for (let i = 0; i < 5; i++) { if (i === 2) continue; result += i; } console.log(result);
Attempts:
2 left
๐ก Hint
The continue statement skips the current loop iteration when i equals 2.
โ Incorrect
The loop adds numbers 0 to 4 to the string except when i is 2, which is skipped by continue. So the output is "0134".
โ Predict Output
intermediate2:00remaining
Continue in while loop output
What will be logged by this code?
Javascript
let count = 0; let output = ''; while (count < 5) { count++; if (count === 3) continue; output += count; } console.log(output);
Attempts:
2 left
๐ก Hint
The continue skips adding when count is 3.
โ Incorrect
The loop increments count from 1 to 5. When count is 3, continue skips adding it to output. So output is '1' + '2' + '4' + '5' = '1245'.
โ Predict Output
advanced2:30remaining
Continue with nested loops output
What is the output of this nested loop code?
Javascript
let result = ''; for (let i = 1; i <= 3; i++) { for (let j = 1; j <= 3; j++) { if (j === 2) continue; result += `${i}${j} `; } } console.log(result.trim());
Attempts:
2 left
๐ก Hint
The continue skips inner loop when j equals 2.
โ Incorrect
For each i, j runs 1 to 3. When j is 2, continue skips adding. So pairs with j=2 are skipped. Result is '11 13 21 23 31 33'.
โ Predict Output
advanced2:00remaining
Continue in forEach callback
What will this code output?
Javascript
const arr = [1, 2, 3, 4]; let sum = 0; arr.forEach(num => { if (num === 3) continue; sum += num; }); console.log(sum);
Attempts:
2 left
๐ก Hint
continue cannot be used inside forEach callback.
โ Incorrect
The continue statement is invalid inside a forEach callback function and causes a SyntaxError.
๐ง Conceptual
expert2:30remaining
Effect of continue on loop variable
Consider this code snippet. What is the final value of i after the loop ends?
Javascript
let i = 0; while (i < 5) { i++; if (i === 3) continue; i++; } console.log(i);
Attempts:
2 left
๐ก Hint
Notice how continue skips the second increment when i is 3.
โ Incorrect
The loop increments i twice each iteration except when i is 3, where continue skips the second increment. The final i is 5.