Conditional Statements
Learn how to use if, else, and switch statements to implement decision-making in C programs.
Conditional Statements is a free C Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Conditional Statements in C
In C, conditional statements allow a program to make decisions based on certain conditions.
In this lesson, you will learn how to use if, else, and switch statements to control program flow.

2
The if Statement
The if statement executes a block of code only if a condition is true.
Syntax:
if (condition) {
// Code to execute if condition is true
}3
Example: if Statement
This program checks if a number is positive.
#include <stdio.h>
int main() {
int num = 10;
if (num > 0) {
printf("The number is positive.\n");
}
return 0;
}4
if-else Statement
The if-else statement executes one block of code if the condition is true and another block if the condition is false.
Syntax:
if (condition) {
// Code if condition is true
} else {
// Code if condition is false
}5
Example: if-else Statement
This program checks if a number is positive or negative.
#include <stdio.h>
int main() {
int num = -5;
if (num > 0) {
printf("Positive number.\n");
} else {
printf("Negative number.\n");
}
return 0;
}6
Nested if Statements
You can use multiple if statements inside one another.
Example:
if (condition1) {
if (condition2) {
// Code block
}
}7
The switch Statement
The switch statement is an alternative to multiple if-else conditions.
Syntax:
switch (variable) {
case value1:
// Code block
break;
case value2:
// Code block
break;
default:
// Default block
}8
9
Example: switch Statement
This program prints the name of a day based on an integer input.
#include <stdio.h>
int main() {
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
default:
printf("Invalid day\n");
}
return 0;
}10
Summary
In this lesson, you learned:
- How to use
if,if-else, andswitchstatements. - How to use nested
ifstatements for complex conditions. - The difference between
if-elseandswitch.
Next, we will explore looping structures in C!

Frequently asked questions
Is the “Conditional Statements” lesson free?
Yes — the full text of “Conditional Statements” is free to read here on the web, and the C Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.
What will I learn in “Conditional Statements”?
Learn how to use if, else, and switch statements to implement decision-making in C programs. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Conditional Statements” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Conditional Statements
- Looping Structures
- Logical and Comparison Operators