Bummer! This is just a preview. You need to be signed in with an account to view the entire instruction.
- The for Loop 4:52
- Create a for Loop 1 objective
- Dynamically Display HTML with a Loop 6:52
- Exit a Loop
- Terminate a Loop 1 objective
- The Refactor Challenge 3:00
- The Refactor Challenge – One Solution 3:05
- The Refactor Challenge – Duplicate Code 6:01
- Review for Loops and Exiting Loops 6 questions
- Refactor Code with a Loop 1 objective
Instruction
Exit a Loop
In each of the three types of loops you've worked with so far, there's some "exit" condition. In other words, when a specific condition is no longer true
, like a counter variable is no longer less than 10
, or less than or equal to 100
, the loop ends.
for ( let i = 0; i <= 100; i++ ) {
// code to run
}
But that's not the only way to exit a loop. JavaScript includes a "...