Search Result
Details here...

Control Structure in C

Previous

Type Conversion in C

Next

If...Else Statement


Control Structure or flow, is the order in which individual statements, instructions or function calls of a program are executed or evaluated. It is the order in which the compiler executes the instructions.

In C, there are three basic control structures:

  • Sequential Control Structure
  • Conditional Control Structure
  • Repetitive Control Structure

1. Sequential Control Structure

Sequential Control structure is the flow of control that is executed in the same order as it is written. It means, the control flows from one statement to the next statement. All the programs written before in this course are based on sequential control structure, as other control structures are not yet introduced.

It is obvious that a program doesn't necessarily have to run from one statement to the next statement. The programmer may want other ways of executing, like jumping from one statement to another, skipping a statement, or repeating a statement, even only executing a statement if some condition is satisfied.

2. Conditional Control Structure

As discussed above, conditional control structure is the flow of control that is executed only if some condition is satisfied. For example, we deal with if-else statements in our life.
If I loved the course at Coderslap
    Then I would like to learn more from here
else
    I will probably switch to another course (please don't)
The above condition is faced even in programming. We may need to execute some code if some condition is satisfied, or we may need to execute some code if some condition is not satisfied.

For this, we use if...else statement, switch statement, and ternary operator in C. We will learn about these in the next chapters.

3. Repetitive Control Structure

Repetitive control structure is the flow of control that is executed for some finite number of times, as specified. For example, we deal with while loop in our life.
while I am not bored
    I will keep doing this
The above condition is faced even in programming. We may need to execute some code some number of times, and for this, we use Loops in C. There are For loop, While loop, and Do-While loop in C. We will learn about these in the coming chapters.
By darpan.kattel
Previous

Type Conversion in C

Next

If...Else Statement