Control Flow

Updated: 04/26/2017 by Computer Hope

flow of controlAlternatively referred to as flow of control, control flow (when referring to computer programming) 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; used to determine what section of code is run in a program at a given 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 within the curly brackets {} after the "if" statement is executed. Otherwise, the code within 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