What Is The Basic Flow Of Program Execution?

The basic flow of program execution is Control Flow. 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.

To summarize, there are seven types of control flow statements:

  • Sequential
  • Select
  • Iterate
  • Function call
  • Recursive statements
  • Non Determinant statements
  • Concurrent statements