🟩 Chapter 3: Control Statements (Decision Making & Looping)
🔹 1. What Are Control Statements?
They control the flow of execution of a program.
Types:
- Decision-making statements
- Looping statements
- Jump statements
🔹 2. Decision-Making Statements
A. if Statement
if (marks > 33)
cout << "Pass";
B. if–else
if (marks >= 33)
cout << "Pass";
else
cout << "Fail";
C. if–else if–else Ladder
if (marks >= 90)
grade = 'A';
else if (marks >= 75)
grade = 'B';
else
grade = 'C';
D. Nested if
if (a > 0) {
if (a % 2 == 0)
cout << "Positive Even";
}
E. switch Statement
switch(choice) {
case 1: cout << "Add"; break;
case 2: cout << "Subtract"; break;
default: cout << "Invalid";
}
🔹 3. Looping Statements
A. for Loop
for (int i = 1; i <= 5; i++) {
cout << i << " ";
}
B. while Loop
int i = 1;
while (i <= 5) {
cout << i << " ";
i++;
}
C. do–while Loop
int i = 1;
do {
cout << i << " ";
i++;
} while (i <= 5);
D. Nested Loop
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
cout << "* ";
}
cout << endl;
}
🔹 4. Jump Statements
- break → exit from loop/switch
- continue → skip current iteration
- return → exit from function
Example:
for (int i = 1; i <= 5; i++) {
if (i == 3) continue;
cout << i << " ";
}
