Please enable JavaScript to use CodeHS

Chapter 2

JavaScript Control Structures

2.7 While Loops

While Loop In Action

While Loop Countdown

While Loops with User Input

Beware of Infinite Loops

Check Your Understanding

  1. Invalid Answer

Exercise: Inventory


Term Definition
Loop A loop is a way to repeat code in your program.
While Loop Lets us repeat code as long as something is true.
Condition A condition is code that you put inside an if statement or while-loop.
Control Structure A control structure lets us change the flow of the code.
Edge Case An edge case is a problem in your code that only occurs in extreme situations.
Fencepost Problem A problem when using a while loop where you forget one action at the beginning or the end.
Counter A variable used to count the number of times an action has been performed
Iterate A single run through the instructions contained a loop