The flow of programming is linear. Meaning the program executes code from top to bottom. Just as we, humans, read left to right and top to bottom... well Americans... so does the program. We can control the flow of our program by using conditional statements (If/Else), loop statements (for, while, do while), and Functions. Control flow is an essential part of coding. Let's take a look at some control flow statements:
CONDITIONAL STATEMENTS
The if state will run a block of code if the condition returns true. If the condition returns false it will run the else code block.
if (condition) {
// Executes if condition is true
} else {
// Executes if condition is false
}
LOOP STATEMENTS
Loop statements break the linear flow of code by repeatedly looping through the code block until the condition returns false and then it breaks out.
while (condition) {
// Executes while condition is true
}
FUNCTIONS
Functions execute a block of code and then breaks out to continue the original flow.
function break() {
console.log("Executing block of code.");
}
These are not the only ways you can control the flow of programming just some basic ways. Get comfortable with these and I believe you will do fine with other control follow statements.