C++ Control
Statements
An Overview of Selection, Iteration, and Jump
Statements
Introduction
Control statements in C++ determine the flow of
execution in a program. They include:
- Selection Statements (if, if-else, switch)
- Iteration Statements (for, while, do-while)
- Jump Statements (break, continue, goto, return)
Selection Statements
Used for decision-making in C++.
1. if statement
2. if-else statement
3. switch statement
Example:
if (x > 0) {
cout << 'Positive';
} else {
cout << 'Negative';
}
Iteration (Looping)
Statements
Used for repeating a block of code multiple times.
1. for loop
2. while loop
3. do-while loop
Example:
for (int i = 0; i < 5; i++) {
cout << i;
}
Jump Statements
Used to alter the flow of execution in a program.
1. break - Exits a loop or switch statement.
2. continue - Skips the rest of the loop iteration.
3. goto - Jumps to a labeled statement.
4. return - Exits a function.
Example:
for (int i = 0; i < 5; i++) {
if (i == 3) break;
cout << i;
}
Conclusion
C++ control statements help in controlling the
flow of execution.
- Selection statements enable decision-making.
- Iteration statements allow repetition.
- Jump statements modify program flow.
Understanding these is essential for efficient
programming.