Overview
Control flow is a set of language constructs that tell a program which pieces of code to execute, and under which conditions to execute them.
The simplest example of control is the the if statement. consider the following code:
let age = 12;
if(age-10 > 0){
print("greater than");
}
else{
print("less than");
}
The if statement is structured like the following:
if(expression){
code to execute if true
}
else{
code to execute if false
}
The if statement takes an expression and evaluates it. If the expression equals true, then the first block of code is executed, otherwise the second block is executed.
For Control Flow
A very important control flow statement is the for statement. It is used to iterate over all the elements of an array. Consider the following:
let data = [1,2,3,4,5];
for(let item of data){
print(item);
}