Control flow

Updated: 11/13/2018 by Computer Hope

flow of controlIn computer programming, control flow or flow of control is the order function calls, instructions, and statements are executed or evaluated when a program is running. Many programming languages have what are called control flow statements, which are used to determine what section of code is run in a program at any time. An example of a control flow statement is an if/else statement, shown in the following JavaScript example.

var x = 1;
if (x === 1) {
window.alert("x is equal to 1.");
}
else {
window.alert("x is not equal to 1.");
}

In this example, if the variable x is set equal to 1, then the code in the curly brackets {} after the "if" statement is executed. Otherwise, the code in the curly brackets after the "else" statement is executed. This code works to control the flow of the program, depending on the value of the variable x.

Note: Control flow and flow control are different terms, not to be used interchangeably.

Execute, Goto, If statement, Label, Programming terms, Subroutine