Control Structure
When a computer program is executed, the execution control moves from one statement to another statement to take actions on program statements. C-language provide features to control; the flow of execution in a program. The statements that are used to control the flow of execution in a program are called control structures.There are three kinds of control structures.
- Sequence Structure
- Selection Structure
- Repetition Structure
- Sequence Structure
In a sequence structure, the statements of a program are executed in the same order in which they are written in the program. The statements are executed one after the other. All statements of the program are executed. For example, a set of statements is written below.Statement - 1 ;
Statement - 2 ;
|
Statement - n ;
All Statement from Statement-1 to Statement-n will be executed in sequence.
- Selection Structure
The selection structure is used for selecting a statement or a group of statement for execution on the basis of a given condition. The selection structure is also known as decision structure.
The instruction of the program are written in a sequence but selection structure are used for making decisions. The given condition is tested. If given condition is true, then statement(s) that follow the selection structure, are executed. Otherwise these are ignored and alternative path is followed.
In C, the most important selection structures are as follows:
- The if statement
- The if-else statement
- The switch statement
- Repetition Structure
Repetition structure is used to execute a statement or a set of statements repeatedly as long as the given condition remains true. Repetition structure is also known as iteration structure or loop structure.
C-language provides the following repetition or loop structures:
- while loop
- do-while loop
- for loop
No comments:
Post a Comment
Thanks For Visiting Here...!! I will Reply you as soon as possible.