Control Structure
A statement used to control the flow of execution in a program is called control structure. The instructions in a program can be organized in three kinds of control structural control execution flow. The control structures are used to implement the program logic.
Types of Control Structures
Different types of control structures are as follows:
Sequential Structure
The sequential structure executes the statements 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. It means no statement is skipped and no statement is executed more than once.
Sequential Structure Example
Suppose a program inputs two numbers and displays average on screen. The program uses two statements to input numbers, one statement to calculate average and one statement to display average number. These statements are executed in a sequence to find the average number. All statements are executed once when the program is executed. It is an example of sequential control structure
Conditional Structure
The conditional structure executes a statement or set of statements based on a condition. It executes a statement if the given condition is true and ignores. when the condition is false. It is also called decision-making structure or selection structure.
Different types of conditional structures in C++ are as follows:
- if
- if-else
- if-else-if
- switch
Conditional Structure Example
Suppose a program inputs the marks of a student and displays a message on screen. whether the student is pass or fail. It displays Pass if the student gets 40 or more than 40 marks. It displays Fail when the marks are below 40. The program checks the marks before displaying the message.
Iterative Structure
The iteration structure executes a statement or set of statements repeatedly for a specific number of times. It is also called repetition structure or loop.
Different types of loops available in C++ language are as follows:
- while loop
- do...while Loop
- for loop
Execution of Iterative Statements
Suppose the user needs to display a message of "I love USA" on screen for 100 times. It is time consuming to perform this task using control sequence structure. However, it is very easy to perform this task using repetition structure. A single loop statement can display the message for 100 times.
Types Of Errors In Best Programming's
Install Turbo C and C++
Basic Structure of C++ Program
Data Process Automation
Best Programming Languages