What you’ll learn
- Why loops are a programmer's superpower
whileloops- Infinite loops (and how to escape them)
forloops, the most common loopdo...whileloops- Skipping and stopping with
continueandbreak - Looping through the letters of a string
- Loops inside loops, FizzBuzz, and a guessing game
The pages
Eleven pages, about 15 minutes.
- Why Loops? Picture this. You were chatting in class (again), and your teacher has given you a punishment: write "I will not talk…
- The while Loop The simplest loop is the while loop. It keeps repeating a block of code while a condition is true. It looks a lot like…
- Infinite Loops: Buggsy's Favorite Trap What happens if you forget the update? countdown stays at 5 forever. 5 > 0 is true forever. So the loop runs…
- The for Loop The while loop has its three ingredients scattered around: the starting point before the loop, the condition at the…
- The do...while Loop There's one more kind of loop, and it's a slight twist on while. A do...while loop runs the body first, and then…
- break and continue Sometimes you want to change how a loop behaves partway through. Two special keywords help. break stops the loop…
- Looping Over Strings Remember that strings have a length and each character has an index, starting from 0? That makes them perfect for…
- Loops Inside Loops You can put a loop inside another loop. This is called a nested loop. For every single iteration of the outer loop…
- The Classic: FizzBuzz There's a famous little programming challenge called FizzBuzz. It's been used for years in job interviews, because…
- Mini Project: The Number Guessing Game Let's build a proper game! The computer picks a secret number from 1 to 100, and you have to guess it. After each…
- Recap The key ideas of Grade 5, JavaScript loops, on one page. A loop repeats a block of code. Each repetition is called an…
Reading is step one
CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.