if / else if / else
int score = 72;
if (score >= 70) {
cout << "First Class" << endl;
} else if (score >= 60) {
cout << "Second Class Upper" << endl;
} else {
cout << "Keep practicing" << endl;
}
C++ uses { } to group more than one statement inside a branch -- a single statement needs no braces at all.
for loops
for (int i = 0; i < 5; i++) {
cout << i << endl;
}
for (int i = 0; i < 5; i++) runs with i = 0, 1, 2, 3, 4 -- 5 iterations, stopping as soon as i < 5 becomes false.
while loops
int count = 0;
while (count < 3) {
cout << count << endl;
count = count + 1;
}
break and continue
for (int i = 0; i < 10; i++) {
if (i == 5) break; // exits the loop entirely
if (i % 2 == 0) continue; // skips to the next iteration
cout << i << endl;
}
Why This Matters for Your Exams
A C++ for loop's condition is checked BEFORE each iteration, including the first -- so for (int i = 0; i < 5; i++) never runs at all if the starting condition is already false. Off-by-one errors here usually come from miscounting whether the final value is included.
Try it yourself
lock
Real-time practice is a paid add-on
Reading units and the practice quiz are free. Pay once to unlock running real code for CPP.

