A statement that is used for control the program running is called Control structure. There are three types of control structure that are used to control the program execution. Program logic can be implemented by a control structure. Some types of control structure are as follow:
![]() |
control structure |
Types of Control Structures
- Sequence
- Selection
- Loop
Sequence Structure
The statement that are use in same order execute in which they are Specified. It work in sequence. The control first enter in first statement after the execution of first than control moves to the next statement and this continue as long as end. In sequence statement there is no statement skip and never more than one statements execute.
Example
Suppose that a program is use for enter two numbers and both numbers display Sum. First control enter first number and take value of first number and after the control enter in second and receive the value of second number. And in last it add the both numbers.
The process is continue in a sequence. In sequence structure there is no statements skip and never a statement execute more than one. In this, structure the control first enter in first statement after it moves to the next this process continue whenever the numbers of statements remain.
Selection Structure
In this structure is used to select a statement or a set of statement on basis of condition. In selection phase a line or set of line is execute if the given values true otherwise if the condition false than it execute the else option.
In a this phase there is no both values execute and never are both skip.
There is some example of selection are as follow:
- IF statement
- If-Else statement
- Nested if
- Switch statement
Example
Suppose that in selection structure a student marks that display message on screen and than show the result pass and fail result. If the marks are greater than are equal 40 than the result show on screen otherwise the result show on screen is fail.
A programmer enter the marks 50 than the condition true the result show on screen is Pass. It is an example of selection structure.
Suppose that programmer write a program that show the pass and fail. if the students greater that are equal to 40 than the result showed on screen is Pass, otherwise the result is fail. During the program execution the user enter marks 23 the control first enter if condition and checked it, the condition not match it means that the result pass is not shows on screen after it automatically the result on screen on fail.
Loop
A loop structure is use to repeat a statement or set of statement that are repeatedly as well as the condition remain true.Loop structure is also known the Iteration structure.
There are some example of Loop are as follow:
- While loop
- Do-While loop
- for loop
Example
Suppose that we want display the message I LOVE PROGRAMMING 1000 times on screen that the programmer used the Loop. This loop is easy to perform that is the reason the most of the user use the loop for programs.
A single loop can display the message on screen 1000 times. First of control enter in initialization phase after pic up the value it moves the condition, first of all the condition the condition true and after the control enter to statement and in last the value increase or decrease.
After it the control again move and enter in condition this process continue as well as long the condition remain true. Finally the condition become false and than control skip the loop.
Related Topics
For more detail visit
No comments:
Post a Comment
Thanks for Visiting