BCA / B.Tech 12 min read

Control Statements in C++

Control Statements in C++:


In programming, Control Statements are used to control the flow of a program. Whenever we need to make a decision during a program or repeat a specific task multiple times, control statements are used. There are mainly three types of control statements in programming languages like C++: Sequential, Decision-Making, and Looping.

Sequential Control Statements:
This is the simplest type where all instructions are executed one after another, in the order they are written.

Decision-Making Control Statements:
These are used when the program needs to perform different actions based on a condition. These include:
  • if Statement: Executes instructions if a condition is true.
  • if-else Statement: Executes one block of code if the condition is true, and another if it is false.
  • else-if Ladder: Used to check multiple conditions.
  • switch Statement: Used to execute instructions based on different values of a variable.

Looping Control Statements:
These are used when we need to execute a block of code multiple times. These include:
  • while Loop: Runs as long as a condition is true.
  • do-while Loop: Runs at least once, and then continues as long as a condition is true.
  • for Loop: Used when we need to run a loop a fixed number of times.

Break and Continue Statements:
  • break Statement: Used to exit a loop or switch statement immediately.
  • continue Statement: Used to skip the current iteration of a loop and move to the next one.