Control flow

Updated: 12/31/2022 by Computer Hope
flow of control

In 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 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 equals 1.");
}
else {
window.alert("x does not equal 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