CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy C · 7 min · free

Decision Making in C: if, else if and switch

7 min4 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

C makes decisions with if, if-else, the else if ladder, nested if and switch; in C, 0 is false and non-zero is true. In a switch, a missing break makes the code fall through to the next cases.

Follows the syllabus of: GSEB Std 10 Computer Studies

On screen in this lesson

Conditions in C

A condition is a question: true or false
In C, 0 means false; any non-zero means true
== compares, but = stores a value
Conditions go inside round brackets ( )

How the ladder is checked

Conditions are checked from top to bottom
The first true condition wins
The final else runs only if all are false
Put the highest range first

Rules of switch

Works with int or char values only
Case labels must be constants, like 3 or 'A'
No two cases can have the same value
break stops fall-through; default is optional

if-else ladder vs switch

Pointelse if ladderswitch
Checksany conditionequality only
Ranges like >= 50yesno
float valuesyesno
Many fixed choiceslong to writeneat and clear

Why avoid goto

Jumps make the flow hard to follow
Many gotos make spaghetti code
Bugs are hard to find and fix
Use if, loops and break instead

Quick recap

if runs code only when the condition is true
else if ladder: the first true condition wins
Nested if: an if inside another if
switch needs break, or it falls through
Avoid goto; use if and loops instead

Quick answers

Why does if (marks >= 33); print Pass even for 20?

The semicolon ends the if, so printf always runs.

What happens without break in a switch?

It falls through and runs the cases below.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. In a switch, if you forget one small word, break, your program prints three answers instead of one. Why? Today we will learn if, if else, the else if ladder and nested if. Then we will learn switch case with break, and goto, with the reason to avoid it.

Every decision starts with a condition. A condition is a question whose answer is true or false, like marks greater than or equal to thirty three. In C, zero means false, and any value that is not zero means true. Double equals compares two values, but one equals sign stores a value. And in C, the condition must always be inside round brackets.

The if statement runs a statement only when the condition is true. Marks is forty five, and forty five is thirty three or more, so it prints Pass. The last printf is not part of the if, so it always runs. Without curly braces, only the one statement just after the if belongs to it.

If else gives two paths, one for true and one for false. The wallet balance is one hundred fifty rupees, and the plan costs one hundred ninety nine. Is the balance greater than or equal to the plan? No. So the else part runs and prints Add money. Curly braces group many statements into one block.

Here is a trap that board exams love. Look at the semicolon right after the if bracket. That semicolon is an empty statement, so the if controls nothing. The printf is now a normal line that always runs. So even with twenty marks, it prints Pass. Never put a semicolon after the if condition.

When there are more than two paths, we use an else if ladder, drawn here as a flowchart. First we read the marks. The first diamond asks, marks seventy five or more? If yes, print Grade A. If no, the next diamond asks, marks fifty or more? If yes, print Grade B. If both answers are no, the flow reaches the bottom and prints Grade C.

Here is the same ladder in C. Marks is sixty eight. Is it seventy five or more? No. Is it fifty or more? Yes, so it prints B, and the rest of the ladder is skipped. Pause and predict. What prints if marks is exactly seventy five? A, because greater than or equal to includes seventy five.

Remember four rules for the ladder. C checks the conditions from top to bottom. The first condition that is true wins, and everything below is skipped. The final else runs only if every condition above is false. So when you check ranges, put the highest range first, or seventy five would wrongly get Grade B.

A nested if is an if written inside another if. The inner question is asked only when the outer answer is true. At a cinema, ticket is one, which means true, so we go inside. Then we check the age. Sixty five is sixty or more, so it prints Senior, for a senior citizen seat. If ticket were zero, nothing would print at all.

A switch compares one value with many fixed choices. Think of a school timetable, where each day number has a first period. Here the day number is three. C jumps straight to case three and prints Science. Break then exits the switch. Default runs when no case matches, like an else.

Now the hook from the start. Here no case has a break. The value is two, so C jumps to case two and prints Two. But without break, it does not stop. It falls through and runs every line below, printing Three, and then End. This is called fall through, and it is why three answers appear instead of one.

Learn the rules of switch for your exam. The switch value must be an integer or a character, never a float or a string. Each case label must be a constant, like three or the character A, not a variable. Two cases cannot have the same value. Break stops the fall through, and the default case is optional.

When should you use each one? An else if ladder can check any condition, but switch only checks if a value is equal to a case. A ladder can test ranges like fifty or more, and switch cannot. A ladder works with float values, and switch does not. But for many fixed choices, like a menu, switch is neater and easier to read.

C also has goto, which jumps straight to a label. A label is a name followed by a colon, here top. The program prints n and adds one. If n is three or less, goto jumps back to top. So it prints one, two, three. It works, but there is a problem.

Here is why good programmers avoid goto. Jumps make it hard to follow which line runs next. A program full of gotos becomes spaghetti code, tangled like a plate of noodles. Bugs in such code are hard to find and fix. The same job can always be done more clearly with if, loops and break, which you will learn next.

Let us revise what we learned today. An if runs its code only when the condition is true, and never put a semicolon after the condition. In an else if ladder, the first true condition wins. A nested if is an if inside another if. A switch needs break after each case, or it falls through. And avoid goto, because if and loops do the job more clearly.

Courses that teach this

CourseUnit
GSEB Std 10 Computer StudiesProgramming Fundamentals & C Language
Programming All levels CFile Handling and the Preprocessor

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.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →