Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

What is Control Statement in C? Types, Uses, and Code Examples

By Mukesh Kumar

Updated on Mar 03, 2025 | 17 min read

Share:

A control statement in C is used to control the flow of execution based on certain conditions. These statements allow your code to make decisions, repeat actions, or jump to different parts of the program.

In this article, you’ll learn what a control statement is in c, how each control statement works and how to use them effectively in your C programs for better control and optimization.

What is Control Statement in C and Why Does It Matters?

In C programming, a control statement is a statement that directs the flow of program execution based on certain conditions. These statements are used to determine the order in which other statements are executed.  

Control statements help structure your program in a way that allows it to make decisions, repeat actions, or jump to different parts of the code based on specific conditions. 

For example, you might use a control statement to check if a user input is valid, or if a loop should continue running. They are essential for building programs that are interactive, flexible, and efficient.

Importance of Control Statement in C

Understanding the types of control statements in C and how to use them effectively is crucial to writing functional and efficient programs. Let’s explore why they matter:

  • Direct Execution Flow: Control statements allow you to guide the execution of your program, making it adapt to different conditions and inputs. This is where the decision control statement in C comes into play, allowing your program to make decisions based on specific conditions.
  • Conditional Logic: With control statements like ifelse, and switch, you can execute certain sections of code only when specific conditions are met. For example, you can check if a number is positive or negative and execute different actions accordingly.
  • Repetition of Actions: Control statements like loops (forwhiledo-while) let you repeat actions multiple times without writing repetitive code. This is especially useful when you need to perform the same task for multiple data points or iterations.
  • Code Readability and Structure: Well-organized control statements improve the clarity and flow of your code, but poorly structured ones can reduce readability and performance. By clearly defining how the program should behave in different situations, they help anyone reading your code understand its flow quickly.
  • Optimized Code: By using control statements effectively, you can write more optimized programs that execute only necessary tasks, improving performance and reducing resource consumption.

To deepen your understanding of control statements in C and programming concepts, explore upGrad’s computer science courses. You’ll not only grasp the theoretical foundations but also learn how to apply them to real-world projects, making you job-ready in fields like software development and system programming.

Now that you understand the basics, let’s dive into the different types of control statements in C and see how each one works with real-world examples.

Types of Control Statement in C: Concepts, Examples, and Implementation

In this section, you’ll explore the main categories of control statements in C. These include decision control statements for making choices, loop control statements for repeating actions, and jump control statements for directing the program flow.

Each category includes examples to show how to use them.

Decision Control Statement in C

In C programming, decision control statements are used to make decisions based on specific conditions. These statements allow the program to choose different paths based on whether a condition is true or false. 

They are a core concept in the types of control statements in C, and understanding them will help you write dynamic and interactive programs.

The most common decision control statements in C are the if statement, if-else statement, nested if, and the else-if ladder. Let's break them down one by one.

1. If Statement

The if statement evaluates a condition, and if it’s true, the code block inside it executes. If the condition is false, the program moves on to the next statement.

Syntax: 

if (condition) {
    // Code to be executed if the condition is true
}

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int number = 5;
    
    if (number > 0) {
        printf("The number is positive.\n");
    }
    
    return 0;
}

Output: 

The number is positive.

Also Read: Control Statements in Java: What Do You Need to Know in 2024

2. If-Else Statement

The if-else statement works similarly to the if statement, but provides an alternative code block to execute if the condition is false.

Syntax: 

if (condition) {
    // Code if condition is true
} else {
    // Code if condition is false
}

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int number = -3;
    
    if (number > 0) {
        printf("The number is positive.\n");
    } else {
        printf("The number is negative or zero.\n");
    }
    
    return 0;
}

Output: 

The number is negative or zero.

3. Nested If Statement

nested if statement occurs when one if statement is placed inside another if. This allows you to evaluate multiple conditions.

Syntax: 

if (condition1) {
    if (condition2) {
        // Code to be executed if both conditions are true
    }
}

Flowchart:  

Example Code: 

#include <stdio.h>

int main() {
    int age = 20;
    
    if (age >= 18) {
        if (age < 21) {
            printf("You are an adult but not yet 21.\n");
        } else {
            printf("You are 21 or older.\n");
        }
    }
    
    return 0;
}

Output: 

You are an adult but not yet 21.

4. Else-If Ladder

The else-if ladder is used when you need to test multiple conditions. It’s a sequence of if statements, each checking a different condition. When a condition is true, the corresponding block of code runs, and the rest are ignored.

Syntax: 

if (condition1) {
    // Code if condition1 is true
} else if (condition2) {
    // Code if condition2 is true
} else if (condition3) {
    // Code if condition3 is true
} else {
    // Code if none of the conditions are true
}

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int number = 10;
    
    if (number < 0) {
        printf("The number is negative.\n");
    } else if (number == 0) {
        printf("The number is zero.\n");
    } else {
        printf("The number is positive.\n");
    }
    
    return 0;
}

Output: 

The number is positive.

5. Switch Statement 

The switch statement in C is a decision control statement that allows you to choose between multiple options based on the value of a variable or expression. 

It is especially useful when you have a single variable that could match multiple possible values, and you need to execute different blocks of code depending on the matching value.

Syntax: 

switch (expression) {
    case value1:
        // Code to be executed if expression == value1
        break;
    case value2:
        // Code to be executed if expression == value2
        break;
    case value3:
        // Code to be executed if expression == value3
        break;
    default:
        // Code to be executed if expression doesn't match any case
}
  • expression: This is the variable or expression that is being evaluated.
  • case: Each case represents a possible value of the expression. If a case matches, the corresponding block of code will execute.
  • break: The break statement exits the switch block once a match is found and the corresponding code has executed. Without it, the program will continue executing the next case statements even if a match is found (this is known as "fall-through").
  • default: This is an optional block that executes if none of the cases match the expression.

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int day = 3;
    
    // Switch statement to print the name of the day based on its number
    switch (day) {
        case 1:
            printf("Monday\n");
            break;
        case 2:
            printf("Tuesday\n");
            break;
        case 3:
            printf("Wednesday\n");
            break;
        case 4:
            printf("Thursday\n");
            break;
        case 5:
            printf("Friday\n");
            break;
        case 6:
            printf("Saturday\n");
            break;
        case 7:
            printf("Sunday\n");
            break;
        default:
            printf("Invalid day\n");
    }
    
    return 0;
}

Output: 

Wednesday

Explanation:

  • In this example, the value of the variable day is 3. The switch statement checks each case in sequence.
  • When it reaches case 3, it matches the value of day and executes the corresponding block, printing "Wednesday".
  • After executing the code for case 3, the break statement ensures that the program exits the switch block, preventing further cases from being checked.
  • If day were outside the range of 1 to 7, the default case would execute, printing "Invalid day".

Also Read: What is a Switch Case in Java & How to Use It?

Now that you've mastered decision-making let's explore how conditional statements in C can fine-tune those choices and add more flexibility to your code.

Conditional Statement in C

In C programming, the conditional statement is a powerful tool that helps control the flow of your program based on conditions. One of the most common types of decision control statements in C is the conditional operator (also called the ternary operator). 

This statement is a concise way of making decisions in a single line, which is particularly useful for simple conditions. 

The syntax of the conditional operator is as follows: 

(condition) ? expression_1 : expression_2;

  • condition: The expression that is evaluated. If it’s true (non-zero), expression_1 is executed.
  • expression_1: This part is executed if the condition is true.
  • expression_2: This part is executed if the condition is false.

Let’s dive deeper with an example to make this concept clearer.

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int num1 = 10, num2 = 5;
    
    // Conditional operator to find the larger number
    int larger = (num1 > num2) ? num1 : num2; // If num1 is greater than num2, assign num1 to 'larger'; otherwise, assign num2.
    
    printf("The larger number is: %d\n", larger); // Output the result
    
    return 0;
}

Output: 

The larger number is: 10

Explanation:

  • Condition(num1 > num2) checks if num1 is greater than num2.
  • If the condition is true (which it is, since 10 > 5), expression_1 (num1) gets assigned to the variable larger.
  • If the condition had been falseexpression_2 (num2) would have been assigned to larger.

In this case, since num1 is greater than num2, the value of larger becomes 10, which is then printed to the screen.

Why use the conditional statement in C?

  • Concise Syntax: The conditional operator helps reduce the number of lines of code when compared to using multiple if statements, especially in simple conditions.
  • Quick Decisions: It’s useful for quick, one-line decisions. For example, checking which number is larger or assigning values based on conditions.
  • Improved Readability: For small decisions, the conditional operator keeps the code clean and easy to read. 

The conditional statement in C is most useful in cases where you need to assign values based on simple conditions. It simplifies your code and makes it easier to understand, especially for simple checks like finding the larger number or choosing between two options.

Now that you’ve made decisions, let’s take control of repetition with loop statements to keep things running smoothly.

Loop Control Statement in C

In C programming, loop control statements are essential when you need to repeat a block of code multiple times based on certain conditions. These loops allow your program to handle repetitive tasks efficiently without having to write redundant code. 

Let’s dive into each of them, understand their syntax, and explore examples.

1. While Loop

The while loop continues executing as long as the specified condition remains true. The condition is checked before executing the loop body, so if the condition is false initially, the body may not run at all.

Syntax: 

while (condition) {
    // Code to be executed as long as the condition is true
}

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int count = 1;
    
    // While loop to print numbers 1 to 5
    while (count <= 5) {  // Condition: keep running as long as count is <= 5
        printf("%d ", count);  // Print current value of count
        count++;  // Increment count by 1
    }
    
    return 0;
}

Output: 

1 2 3 4 5

Explanation:

  • The while loop checks if the condition count <= 5 is true.
  • If true, the loop prints the current value of count and increments it by 1.
  • The loop runs until count exceeds 5.

Also Read: While Loop in Python [With Syntax and Examples]

2. Do-While Loop

The do-while loop is similar to the while loop, but with one key difference: the condition is checked after the loop body is executed. This means the loop body will always run at least once, even if the condition is false initially.

Syntax: 

do {
    // Code to be executed
} while (condition);

Flowchart:

Example Code: 

#include <stdio.h>

int main() {
    int count = 6;
    
    // Do-while loop to print numbers 1 to 5
    do {
        printf("%d ", count);  // Print current value of count
        count++;  // Increment count by 1
    } while (count <= 5);  // Condition is checked after loop execution
    
    return 0;
}

Output: 

6

Explanation:

  • The loop runs once even though the initial value of count is 6, which is greater than 5.
  • Since the condition is checked after the loop body, it executes one time before checking if the condition is true.

3. For Loop

The for loop is used when you know the number of iterations beforehand. It combines the initialization, condition-checking, and increment/decrement in a single line. It is ideal for looping through arrays or repeating tasks a set number of times.

Syntax: 

for (initialization; condition; increment) {
    // Code to be executed
}

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    // For loop to print numbers 1 to 5
    for (int count = 1; count <= 5; count++) {  // Initialization: count = 1, Condition: count <= 5, Increment: count++
        printf("%d ", count);  // Print current value of count
    }
    
    return 0;
}

Output: 

1 2 3 4 5

Explanation:

  • The loop initializes count to 1.
  • It checks the condition count <= 5.
  • If true, it prints the value of count and increments it by 1. This process continues until count exceeds 5.

With conditions and loops in place, it’s time to explore how jump statements can quickly change the course of your program.

Jump Statement in C

Jump statements in C allow you to control the flow of your program by skipping parts of code or jumping to specific locations in the program. These statements are part of the types of control statements in C, and they provide you with flexibility when you need to exit loops early, skip iterations, or return from functions.  

Let’s break down each of these jump statements and explore how they work with examples.

1. Break Statement

The break statement is used to exit from a loop or switch statement before the loop or switch has completed all iterations or cases. It’s commonly used when a specific condition is met, and you want to stop further processing.

Syntax: 

break;

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    // For loop that breaks when count reaches 3
    for (int count = 1; count <= 5; count++) {
        if (count == 3) {
            break;  // Exit the loop when count is 3
        }
        printf("%d ", count);  // Print current value of count
    }
    
    return 0;
}

Output: 

1 2

Explanation:

  • The for loop runs from 1 to 5, but when count becomes 3, the break statement is executed.
  • This exits the loop immediately, so only 1 and 2 are printed.

2. Continue Statement

The continue statement skips the current iteration of a loop and moves to the next iteration. It is often used when a certain condition is met, and you want to skip the rest of the code in that iteration.

Syntax: 

continue;

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    // For loop that skips printing 3
    for (int count = 1; count <= 5; count++) {
        if (count == 3) {
            continue;  // Skip this iteration when count is 3
        }
        printf("%d ", count);  // Print current value of count
    }
    
    return 0;
}

Output: 

1 2 4 5

Explanation:

  • The continue statement is executed when count is 3, causing the loop to skip the rest of the code for that iteration.
  • Therefore, 3 is not printed, and the loop continues with the next iteration.

Also Read: Python Break, Continue & Pass Statements [With Examples]

3. Goto Statement

The goto statement is used to jump to a specific label within your program. While it provides direct control over the flow, it should be used sparingly, as it can make your code harder to read and maintain.

Syntax: 

goto label;
label: 
    // Code to be executed after jump

Flowchart: 

Example Code: 

#include <stdio.h>

int main() {
    int num = 5;
    
    // If num is less than 10, jump to 'end' label
    if (num < 10) {
        goto end;  // Jump directly to the end label
    }
    
    printf("This will be skipped.\n");
    
end:  // Label for jump
    printf("This is where the program jumps to.\n");
    
    return 0;
}

Output: 

This is where the program jumps to.

Explanation:

  • The goto statement causes the program to jump to the end label, skipping the line that prints "This will be skipped."
  • The program then executes the code at the end label.

4. Return Statement

The return statement is used to exit a function and optionally return a value to the calling function. This is commonly used to signal the end of a function's execution and return control to the calling code.

Syntax: 

return value;

Flowchart: 

Example Code: 

#include <stdio.h>

int add(int a, int b) {
    return a + b;  // Return the sum of a and b
}

int main() {
    int result = add(3, 4);  // Call the add function
    printf("The sum is: %d\n", result);  // Output the result
    
    return 0;
}

Output: 

The sum is: 7

Explanation:

  • The add function returns the sum of a and b using the return statement.
  • The main function captures the returned value and prints the result.

Now that you've seen each control statement in action, let's compare them side by side to understand their strengths and when to use each.

Comparison of Control Statements in C

In C programming, each control statement serves a unique purpose, and choosing the right one depends on the task at hand.   

Control Statement

Purpose

Condition Type

Use Case

if-else Decision-making based on a condition Single condition (true/false) Used for simple true/false conditions, like validating input or checking flags.
switch Multi-way decision based on a variable's value Multiple values for one variable Used for checking multiple possible values of a single variable (e.g., menu selection).
for loop Repeating a task a set number of times Range or counter condition Iterating through a collection or repeating a task for a fixed number of times.
while & do-while loop Repeating a task based on a condition True/false condition While is used when the number of iterations is unknown, do-while ensures at least one iteration.

Now that you know how control statements work, let’s explore their pros and cons to understand when and why to use them effectively.

What are Advantages and Disadvantages of Control Statement in C?

Control statements are essential tools in C programming, allowing you to define the flow of execution. But like any tool, they come with their own set of advantages and disadvantages. 

Advantages 

Control statements allow your program to make decisions, repeat tasks, or even jump to different parts of the code.  

Advantage

Explanation

Flexibility Control statements allow your program to adapt to various conditions dynamically.
Efficiency Loops and conditional statements help reduce code redundancy, improving performance.
Readability Well-organized control structures make your code clearer and easier to follow.
Optimal Resource Usage Efficient loops and decision-making reduce unnecessary computations, optimizing program performance.

Disadvantages  

While control statements bring flexibility and efficiency, they also come with some limitations. Misusing them or choosing the wrong type of control statement can make your code more complex, difficult to maintain, or inefficient.

Disadvantage

Explanation

Overuse of if-else Too many nested or complex if-else statements make your code harder to read, debug, and maintain.
Complexity Using multiple nested control statements can result in difficult-to-follow and error-prone code.
Performance Issues Inefficient control flow, especially in loops, can slow down the program, especially with large data sets.
Code Duplication Repetitive control statements across your program can lead to code duplication, increasing maintenance overhead.

The right control statement can greatly improve the performance, readability, and efficiency of your program. Just be cautious of their limitations, especially when dealing with complex conditions and large data sets.

How Can upGrad Help You Advance Your Career in Programming?

upGrad is your go-to partner for mastering essential programming concepts for a successful software development career. With over 10 million learners and 200+ industry-driven courses, upGrad equips you with the skills to stay competitive.

Whether you're advancing in C programming, decision-making, or system design, upGrad helps build a solid foundation for your career.

Here are the top courses: 

You can also get personalized career counseling with upGrad to guide your career path, or visit your nearest upGrad center and start hands-on training today!

Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.

Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.

Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.

Frequently Asked Questions

1. How do control statements in C impact program performance?

2. Can you use multiple control statements together in C?

3. What is the role of the switch statement in C?

4. When should I use a while loop over a for loop in C?

5. What is the difference between break and continue in C control statements?

6. How do nested control statements work in C?

7. What are the practical use cases for goto in C?

8. How does the if-else statement work in C?

9. Can you combine different types of control statements in C for complex decisions?

10. How can control statements improve code readability in C?

11. Are control statements in C the same for all programming languages?

Mukesh Kumar

108 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

Suggested Blogs