Please enable JavaScript to use CodeHS

Chapter 2

JavaScript Control Structures

2.8 Loop and a Half

The Infinite Loop

The Break Statement

The Sentinel

Adding Up Numbers

Check Your Understanding

  1. Invalid Answer

Exercise: Double Sixes

Vocabulary

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.
Sentinel A constant that has the specific purpose of being the value that breaks out of a loop.
Control Structure A control structure lets us change the flow of the code.
Loop-and-a-half A loop, most often set with while(true), that has a break in the loop body.
break statement The `break;` statement breaks out of the current loop, without executing any more code in the loop.
Infinite Loop A loop that has no way of stopping, and will keep looping forever.

Do you have feedback on this lesson? Let us know here
Rate this lesson:

Feedback on this lesson:

Issue found (optional):