Data Structures using C PlusPlus: Chapter 1: Data Abstraction and Overloading

Control Structures of C++

Question: Explain control structures of C++ with suitable examples.

Control Structures

Various control structures are ‒

1. if statement

2. while statement

3. do‒while statement

4. switch case statement

5. for loop

Let us discuss these control structures with the help of simple examples.

 

1. If statement

There are two types of if statements simple if statement and compound id statement. The simple if statement is a kind of if statement which is followed by single statement. The compound if statement is a kind of if statement for which a group of statements are followed. These group of statements are enclosed within the curly brackets.

If statement can  also be accompanied by the else part.

Following table illustrates various forms of if statement



2. While Statement

The while statement is executing repeatedly until the condition is false. The while statement can be simple while or compound while. Following table illustrates the forms of while statements ‒


 

3. do..while

The do...while statement is used for repeated execution. The difference between do while and while statement is that, in while statement the condition is checked before executing any statement whereas in do while statements the statement is executed first and then the condition is tested. There is at least one execution of statements in case of do...while. Following table shows the use of do while statement.


Note that the while condition is terminated by a semicolon.

 

4. Switch Case Statement

From multiple cases if only one case is to be executed at a time then switch case statement is executed. Following table shows the use of switch case statements


 

5. for Loop

The for loop is a not statement it is a loop, using which the repeated execution of statements occurs. Following table illustrates the use of for loop ‒


 

Review Question

1. Explain control structures of C++ with suitable examples.

 

Data Structures using C PlusPlus: Chapter 1: Data Abstraction and Overloading : Tag: Data Structure, C++, C Programing : - Control Structures of C++


Data Structures using C PlusPlus: Chapter 1: Data Abstraction and Overloading



Under Subject


Data Structures using CPlusPlus

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Electron Devices

EC25C01 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Data Structures using CPlusPlus

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Circuits and Network Analysis

EC25C02 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Engineering Drawing - Laboratory

ME25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Data Structures using CPlusPlus - Laboratory

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Devices and Circuits Laboratory

EC25C03 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation