Chapter 6
Getting into the Flow with Loops and Branches
IN THIS CHAPTER
Finding out about if/else branching
Understanding the different types of loops
Using loops to repeat statements
Looping through the values of an array
“It's not hard to make decisions when you know what your values are.”
— ROY DISNEY
In earlier chapters of this book, you learned about linear JavaScript code. However, more often than not, there comes a time (many times, actually) in a program where you need a choice to be made or where you need to alter the straight-ahead logic of a program to repeat statements multiple times with different values. In this chapter, you learn about looping and branching statements.
Branching Out
Looping and branching statements are called control statements because they control the order in which JavaScript statements are run. You can use branching statements to create different paths for the execution of JavaScript code, depending on conditional logic. Loops are the simplest way to group JavaScript statements together in a program.
The logic of a JavaScript program often comes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access