Introduction
C provides four general categories of control structures: sequential, selection, iteration and encapsulation.
Program/Example
A sequential structure is one in which instructions are executed in sequence. For example,
i = i + 1; j = j + 1;
In the selection structure, the sequence of the instruction is determined by using the result of the condition. The statements that can be used in this category are if and switch. For example:
if (a > b) i = i + 1; else j = j +1;
If the condition is true then the statement i = i +1 is executed; otherwise j = j + 1 is executed.7
The iteration structure is one in which statements are repeatedly executed. The iteration structure forms program loops. The number of iterations generally depends on the values of particular variables.
for (i=0; i<5; i++) { j = j + 1; }
The statement j = j + 1 is executed 5 times and the value of i changes from 0 to 1, 2, 3, and 4.
Encapsulation structure is the structure in which the other component structures are included. For example, you can include an if statement in a for loop or a for loop in an if statement.
Explanation
C provides all the standard control structures that are available in programming languages. These structures are capable of processing any information.
No comments:
Post a Comment