0
0
Javascriptprogramming~10 mins

Labeled break and continue in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to break out of the outer loop using a label.

Javascript
outerLoop: for (let i = 0; i < 3; i++) {
  for (let j = 0; j < 3; j++) {
    if (i === 1 && j === 1) {
      [1] outerLoop;
    }
  }
}
Drag options to blanks, or click blank then click option'
Areturn
Bcontinue
Cexit
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'continue' instead of 'break' to exit the loop.
Forgetting to add the label after 'break'.
2fill in blank
medium

Complete the code to continue the outer loop when a condition is met.

Javascript
outer: for (let i = 0; i < 3; i++) {
  for (let j = 0; j < 3; j++) {
    if (j === 1) {
      [1] outer;
    }
  }
}
Drag options to blanks, or click blank then click option'
Acontinue
Bbreak
Creturn
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'continue' to skip iterations.
Not specifying the label after 'continue'.
3fill in blank
hard

Fix the error in the labeled continue statement.

Javascript
outerLoop: for (let i = 0; i < 2; i++) {
  for (let j = 0; j < 2; j++) {
    if (i === j) {
      [1] outerLoop;
    }
  }
}
Drag options to blanks, or click blank then click option'
Acontinue
Bcontinuee
Cbreakk
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling 'continue' as 'continuee'.
Using 'break' when 'continue' is needed.
4fill in blank
hard

Fill both blanks to correctly use labeled break and continue in nested loops.

Javascript
outer: for (let i = 0; i < 3; i++) {
  inner: for (let j = 0; j < 3; j++) {
    if (i === 1 && j === 1) {
      [1] outer;
    }
    if (j === 2) {
      [2] inner;
    }
  }
}
Drag options to blanks, or click blank then click option'
Abreak
Bcontinue
Creturn
Dexit
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'break' and 'continue' keywords.
Using wrong labels or missing labels.
5fill in blank
hard

Fill all three blanks to create a labeled loop that breaks and continues correctly.

Javascript
outerLoop: for (let i = 0; i < 4; i++) {
  innerLoop: for (let j = 0; j < 4; j++) {
    if (i === 2 && j === 2) {
      [1] outerLoop;
    }
    if (j === 3) {
      [2] innerLoop;
    }
    console.log(i, j);
  }
  if (i === 3) {
    [3];
  }
}
Drag options to blanks, or click blank then click option'
Abreak
Bcontinue
Creturn
Dbreak outerLoop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' without label to exit outer loop.
Using 'continue' without label to skip inner loop.
Confusing 'return' with 'break' or 'continue'.