KwickAcademy Cyber Safety and Ethics · 7 min · free
Control Statements in C++: if, switch and Loops
C++ control statements change the order code runs: if and switch choose a path, loops repeat, break and continue jump.
Follows the syllabus of: GSEB Std 11 Computer Studies, NIOS Senior Secondary Computer Science (330)
On screen in this lesson
What are control statements?
| Normally statements run top to bottom |
| Selection: if, if-else, switch choose a path |
| Iteration: while, do-while, for repeat steps |
| Jump: break and continue change the flow |
Watch out: = versus ==
| == compares: if (marks == 33) |
| = stores: if (marks = 33) is always true |
| Put braces { } around two or more statements |
| No semicolon right after if (...) |
switch rules
| Works with int and char values, not float or strings |
| Each case needs a constant, like case 2 or case 'A' |
| Without break, control falls through to the next case |
| default is optional and runs when nothing matches |
Three loops compared
| Loop | Checks | Runs at least |
|---|---|---|
| while | Before the body | 0 times |
| do-while | After the body | 1 time |
| for | Before the body | 0 times |
Quick recap
| if, else if and switch choose a path |
| switch needs break, or it falls through |
| while and for check first; do-while runs once at least |
| break exits a loop; continue skips one round |
| == compares, = stores |
Quick answers
Is if (marks = 33) a comparison?
No. = stores 33, so the condition is always true. Use ==.
Which loop runs at least once?
do-while.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
What does the switch print?41 sec
Which loop always runs once?41 sec
Does continue stop the loop?40 sec
Why start fact at 1?40 secThe full lesson, in text
Hello students, welcome to Kwickprep. What happens if you forget break in a switch? The program keeps running into the next case! Today we learn how C plus plus makes decisions and repeats work. We will cover if, switch, three loops, break and continue, and exam programs.
First, a new term. A control statement changes the order in which statements run. Normally, statements run one after another, from top to bottom. Selection statements choose one path based on a condition. Iteration statements, also called loops, repeat steps. Jump statements like break and continue move control to another place.
The if statement checks a condition written inside round brackets. A condition is a question whose answer is true or false. Here marks is forty five. Is marks greater than or equal to thirty three? Yes, so it prints Pass. If the answer were no, the else part would run and print Fail.
Here are three traps that exams love. Double equals compares two values. A single equals sign stores a value. So if marks equals thirty three, with one sign, is always true, and it still compiles. When an if controls two or more statements, put them inside curly braces. And never put a semicolon right after the if brackets, because that ends the if immediately.
For more than two paths, we use an else if ladder. Here marks is sixty eight. Is it seventy five or more? No. Is it fifty or more? Yes, so it prints B, and the rest is skipped. Pause and predict. What prints if marks is exactly seventy five? It prints A, because greater than or equal to includes seventy five.
A switch compares one value with many fixed choices, like a school timetable. Day is two, so control jumps to case two and prints Science. Break then exits the switch. Default runs when no case matches, just like else.
Learn four rules about switch. The value must be a whole number type such as int or char, not a float or a string. Each case label must be a constant, like two or the letter A. If you forget break, control falls through and runs the next case too. Default is optional, and it runs only when no case matches.
A while loop repeats a block as long as its condition is true. It checks the condition first, so it is called an entry controlled loop. The counter, named i, starts at one. While the counter is five or less, we print the counter and then add one. When the counter becomes six, the condition is false and the loop stops. Forget the increment, and the loop never ends.
A do while loop runs the block first and checks the condition afterwards. So it is an exit controlled loop, and it always runs at least once. Here the counter is ten, which is already more than five. Still, the block runs once and prints ten. Notice the semicolon after the while line, which is compulsory here.
A for loop keeps three parts in one line, separated by semicolons. The first part starts the counter, the second checks the condition, and the third updates the counter. We use it when we know how many times to repeat. This loop prints the first five multiples of seven.
Let us compare the three loops. A while loop checks before the body, so it may run zero times. A do while loop checks after the body, so it runs at least once. A for loop also checks first, and it is best when the count is known.
The break statement exits the loop immediately. This loop could count to ten. But when the counter equals four, break stops the whole loop. So only one, two and three are printed.
The continue statement skips the rest of the current round and jumps to the next one. When the counter equals three, continue skips the printing line. The loop does not stop, so it goes on to four and five. The output is one, two, four, five.
Now two programs that exams ask often. First, the sum of digits of four seven two. Modulus ten gives the last digit, and dividing by ten removes it. The loop adds two, then seven, then four. When the number becomes zero, it stops and prints thirteen.
Second, the factorial of five. Factorial means multiplying all whole numbers from one up to that number. Fact starts at one, not zero, because anything times zero is zero. The loop multiplies one, two, three, four and five. It prints one hundred twenty.
Let us revise what we learned today. If, else if and switch choose a path. A switch needs break after each case, or it falls through. While and for check the condition first, but do while always runs at least once. Break exits the loop, and continue skips just one round. And remember, double equals compares, while one equals sign stores. Try the digit sum program with your own roll number.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 10 Information Technology (402) | Electronic Spreadsheet (Advanced) using LibreOffice Calc |
| ISC Class 11 Computer Science (868) | Software and Algorithmic Problem Solving |
| GSEB Std 11 Computer Studies | Advanced Scripting |
| NIOS Senior Secondary Computer Science (330) | Module 3: Programming in C++ |
| Programming All levels C++ | Control Flow and Functions |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

