What is program flow called as?

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 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.

. In control flow, each programming statement, each programming instruction, and every function call of a program is executed. The control flow of program execution depends on types of programming language. There exist two types of programming languages: first, imperative programming language, second, declarative programming language.

In the Imperative programming language, the flow of control in programming execution depends on the decision to follow a particular path. Therefore, the sequence of programming instructions is combined to build programming blocks. These programming instruction blocks are used to define lexical scopes.

The flow of control of program execution is altered when the function is called. In this case flow of control has to leave its execution sequence and jump to the function called. Therefore, the control flow of program execution depends on conditional or unconditional branch instructions. 

The flow of program execution is maintained and carried out by the program counter. Different languages implement the control flow of statements differently. They are categorized in the following way:

  • Use of unconditional branching in which control jumps to other programming instructions.
  • Use of conditional branching in which execution of a particular set of instructions depends on the evaluation outcome of a particular condition.
  • The use of iteration is the repeated execution of a particular set of instructions. This execution continues until a particular condition is met.
  • Execution of function programming instructions and after execution of the programming instructions, control is returned to place from where control was transferred.
  • Use of Unconditional halt in which program execution stops and further execution of the program does not occur.


Control flow of program execution is also maintained by using:

  • Labels
  • Goto
  • Subroutines
  • Sequence

Labels

Labels are used to alter the flow of control. Labels are usually associated with unconditional jumps. Labels are placed within programming instructions. When unconditional jump programming instruction is executed, control searches for labels within the programming instruction block in which unconditional jump programming instruction is placed. The lThus, the label works as a landmark within the programming instruction block.

In programming languages such as BASIC, line numbers are used instead of labels. Line numbers are whole numbers allotted to each programming instruction. Line numbers are allotted in increasing order to each programming instruction. BASIC imposes the rule that line numbers must be in increasing order, but it is not necessary that they must be consecutive. For example, after line number 2, line number 6 can come, but it is impossible to give line number 1 to programming instructions.

Goto

GOTO is an unconditional jumping statement that is used to alter the control flow of programming instructions. Goto is often used as a keyword in programming languages. The goto forces the program’s control flow to jump to the location where the label is placed.

Subroutines

In many programming languages, subroutines are also known as functions. This is because functions are used to reduce the program size. The number of times functions are executed on the number of times they are called.

Sequence

It is the sequence of instructions used to follow the execution in an ordered fashion. Writing programming instructions in a sequence is a building block of a program along with iteration or recursion.

Programming instructions are written to accomplish a particular task. To accomplish a particular task, there must be a logical and ordered flow and execution of a set of programming instructions. There must be a mechanism to specify the set of programming instructions to be executed to accomplish a particular task. Different programming languages use different mechanisms to denote the set of programming instructions. This mechanism also influences the control flow of programming instructions. For example, the C, C++, Java, PHP language uses curly brackets {….} to denote the particular set of programming instructions, and Python uses indent to devote a particular set of programming instructions.

Conditional expressions such as if-then-else alter the control flow of execution depending on the evaluation of the conditional expression used in the if-then-else statement. Another control flow statement that is used in programming instructions is Case and Switch statements. In switch, statement control flows to that part of the program to which the value of the switch statement is equal to that of the constant. If the value of the switch statement does not match any of the constants specified, then the default part of the switch statement is executed. Different languages use different ways of executing switch statements. For example, shell scripts use pattern matching to compare switch statement expression values to a particular pattern. If the pattern is not used, then constant can also be used to compare switch expression values. 

Next, the programming construct used to alter the control flow of programming instruction is the loop. Loops are used to execute a particular set of programming instructions repeatedly. Programming instructions within the loop are executed repeatedly until the loop condition becomes false. Loops can also be executed a particular number of times. The number of times loops are executed on the integer value defined in the loop.

There exist cases where loop execution is required an infinite number of times. Infinite loops are executed infinitely until an error arises or a system breakdown occurs. Infinite loops are implemented differently in different programming languages. Unstructured programming language implements it using goto statement, and structured programming language implements it using a specific language grammar.

Recursion is also a control flow statement, a function using recursion calls itself. Thus, recursion is an alternative to iteration. Furthermore, the function that uses recursion has shortcodes as compared to functions that use iterative statements. Thus, recursive function execution time is less as compared to iterative functions.


It is often required in programming that control flow should skip a particular set of instructions even then follow sequential execution of the programming instructions. To achieve this type of program control, flow different programming instructions using different programming constructs. Few of the programming languages use break statements, while others use Exit statements. Break statement breaks the execution of the loop, thus alters the control flow of the statements. Exit statement takes the control flow of program execution out of the program.

The basic flow of program execution is control flow. Basic programming instructions are executed sequentially. This sequential execution can be altered. To alter basic programming instruction execution control flow, different programming languages use different programming constructs. One of the programming constructs used is Exception Handling. Exception handling is used to handle the errors raised during the execution of the programming instructions. On the occurrence of the errors, exception handling uses a catch statement. When an error occurs, statements within the catch block are executed. Exception handling has to try-catch blocks. For one try block, there may be many catch statements.

What is the flow of program?

Program flow is a general term which describes the order in which your lines of code are executed. This means that some lines will only be read once, some multiple times, and others may be skipped completely, depending on the situation. In this first chapter on program flow, we will look at conditional statements.

What are the 3 types of program flow?

There are three basic types of logic, or flow of control, known as:.
Sequence logic, or sequential flow..
Selection logic, or conditional flow..
Iteration logic, or repetitive flow..

What is code flow in programming?

In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

What is program control flow?

The control flow is the order in which the computer executes statements in a script. Code is run in order from the first line in the file to the last line, unless the computer runs across the (extremely frequent) structures that change the control flow, such as conditionals and loops.