Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A Quiz
🧠 Introduction
Control flow statements in C determine the direction in
which a program executes. They allow you to make decisions, repeat actions, and
jump to specific parts of the code. These structures are essential for writing
dynamic and interactive programs.
Without control flow, a C program would execute
linearly—from top to bottom—regardless of conditions or logic. Control
structures make programs smart, efficient, and functional.
✅ Types of Control Flow
Statements in C
C supports three major categories of control flow:
🟡 1. Decision-Making
Statements
These statements execute different blocks of code based on conditions.
🔹 if Statement
Executes a block if the condition is true.
if
(condition) {
// code block
}
Example:
int
age = 18;
if
(age >= 18) {
printf("You are eligible to
vote.\n");
}
🔹 if-else Statement
Provides an alternative path if the condition is false.
if
(condition) {
// if block
}
else {
// else block
}
Example:
int
num = 5;
if
(num % 2 == 0) {
printf("Even number\n");
}
else {
printf("Odd number\n");
}
🔹 else-if Ladder
Evaluates multiple conditions in sequence.
if
(condition1) {
// code
}
else if (condition2) {
// code
}
else {
// code
}
Example:
int
score = 85;
if
(score >= 90) {
printf("Grade A\n");
}
else if (score >= 75) {
printf("Grade B\n");
}
else {
printf("Grade C\n");
}
🔹 Nested if
An if inside another if.
if
(condition1) {
if (condition2) {
// nested code
}
}
Example:
int
age = 20, hasID = 1;
if
(age >= 18) {
if (hasID) {
printf("Access granted\n");
}
}
🔹 switch Statement
Used to check multiple values of a single variable.
switch(expression)
{
case value1:
// code
break;
case value2:
// code
break;
default:
// default code
}
Example:
int
day = 3;
switch(day)
{
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
case 3: printf("Wednesday");
break;
default: printf("Invalid");
}
📋 Comparison Table –
Decision Making
Statement |
Used For |
Supports Multiple
Conditions |
if |
Single condition |
No |
if-else |
Two paths |
No |
else-if |
Multiple conditions |
Yes |
nested if |
Condition
inside another |
Yes |
switch |
Multiple fixed value
checks |
Yes |
🔄 2. Looping Statements
Used for repeating blocks of code.
🔹 for Loop
Best when the number of iterations is known.
for
(initialization; condition; increment) {
// loop body
}
Example:
for
(int i = 1; i <= 5; i++) {
printf("%d\n", i);
}
🔹 while Loop
Checks condition before executing the block.
while
(condition) {
// loop body
}
Example:
int
i = 1;
while
(i <= 5) {
printf("%d\n", i);
i++;
}
🔹 do-while Loop
Executes the block at least once.
do
{
// loop body
}
while (condition);
Example:
int
i = 1;
do
{
printf("%d\n", i);
i++;
}
while (i <= 5);
📋 Comparison Table –
Loops
Loop |
Condition Checked |
Use Case |
for |
Beginning |
Fixed number of
iterations |
while |
Beginning |
Unknown
number of iterations |
do-while |
End |
At least one iteration
required |
🔁 3. Jumping Statements
Used to change the normal flow of execution inside loops or
conditions.
🔹 break Statement
Terminates a loop or switch.
for
(int i = 0; i < 10; i++) {
if (i == 5) break;
printf("%d ", i);
}
Output:
0 1 2 3 4
🔹 continue Statement
Skips current iteration and continues with the next one.
for
(int i = 0; i < 5; i++) {
if (i == 2) continue;
printf("%d ", i);
}
Output:
0 1 3 4
🔹 goto Statement
Jumps to a labeled statement.
goto
label;
label:
printf("Jumped here");
⚠️ Note: goto is rarely
recommended as it makes code hard to maintain.
🔹 return Statement
Exits a function and returns a value.
int
add(int a, int b) {
return a + b;
}
🧰 Real-World Use Cases
🧪 Sample Program: Loop +
Decision
#include
<stdio.h>
int
main() {
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
printf("%d is even\n",
i);
} else {
printf("%d is odd\n", i);
}
}
return 0;
}
📊 Summary Table
Control Type |
Statement |
Usage Example |
Decision |
if, else, switch |
Based on conditions |
Loop |
for, while,
do-while |
Repeating
tasks |
Jump |
break, continue, goto,
return |
Altering flow |
A: Absolutely. C is widely used in systems programming, embedded systems, and performance-critical applications.
A: Just basic computer literacy. No prior programming knowledge is required.
A: Code::Blocks or VS Code with a C plugin is great for beginners.
A: C is a compiled language. It uses compilers like GCC or Clang.
A: With consistent practice, 4–8 weeks is sufficient to grasp core concepts.
A: Pointers and manual memory management can be tricky for beginners.
A: C is not typically used for web apps, but it can handle back-end processes or be integrated via CGI.
A: Each has its use. C is great for low-level control and speed, but C++ and Python offer more abstraction and ease of use.
A: Use a terminal/IDE to compile with gcc filename.c -o output and run with ./output.
A: GitHub, HackerRank, and open-source forums are great places to find beginner to advanced C projects.
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Comments(0)