Control Flow in C Programming

Control Flow in C – A program consists of a number of statements to be executed by the computer.

Not many of the programs execute all their statements in sequential order from beginning to end as they appear within the program.

A C program may require that a logical test is carried out at some particular point within the program. One of the several possible actions will be carried out, depending on the outcome of the logical test. This is called Branching.

In the Selection process, a set of statements will be selected for execution, among the several sets available.

Suppose, if there is a need for a group of statements to be executed repeatedly until some logical condition is satisfied, then looping is required in the program.

These can be carried out using various control statements.

These Control statements determine the “flow of control” in a program and enable us to specify the order in which the various instructions in a program are to be executed by the computer.

Normally, high-level procedural programming languages require three basic control statements:

  1. Sequence instruction
  2.  Selection/decision instruction
  3.  Repetition or Loop instruction

Sequence Instruction

Sequence instruction means executing one instruction after another, in the order in which they occur in the source file.

This is usually built into the language as a default action, as it is with C.

If an instruction is not a control statement, then the next instruction to be executed will simply be the next one in sequence.

Selection/Decision Instruction

Selection means executing different sections of code depending on a specific condition or the value of a variable. This allows a program to take different courses of action depending on different conditions. C provides three selection structures.

This allows a program to take different courses of action depending on different conditions. C provides three selection structures.

C provides three selection structures.

  1. if
  2. if…else
  3. switch

Repetition or Loop Instruction

Repetition/Looping means executing the same section of code more than once.

A section of code may either be executed a fixed number of times or while some condition is true.

C provides three looping statements:

  1. while
  2. do…while
  3. for

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: