Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# ASP.NET MVC ASP.NET Web Forms C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet General Web Development HTML, CSS HTML/CSS Java JavaScript JavaScript, HTML, CSS JavaScript, Node.js Node.js
      Python Python 3.11, Pandas, SQL Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. Python
  4. Mastering Decision-Making Statements in Python: A Complete Guide

Mastering Decision-Making Statements in Python: A Complete Guide

Date- Dec 09,2023 Updated Mar 2026 3611
python decision making statements

1.Conditional Statements:-

a)If Statements:-

The if statement is used to execute a block of statements if a specified condition is true.

Syntax:-

if(condition)

{

Statement 1;

}

Statement 2;


If the condition is true, then statement 1 is executed; otherwise, statement 2 is executed.

b) If-else Statements:-

It allows you to execute different blocks of code based on whether a specified condition is true or false.

Syntax:-

if(condition)

{

Statement 1;

}

else

{

Statement 2;

}

If the condition is true, then the if statement (Statement 1) is executed; otherwise, the else statement (Statement 2) is executed.

c) Multiple-If Statement:

syntax:-

if(condition)

{

Statement1;

}

else if(condition)

{

Statement2;

}

else

{

Statement3;

}

multipleif statements to check multiple conditions sequentially. Eachif statement is evaluated independently, and the corresponding block of code is executed if the condition is true.

d) Nested If Statement:

A nested if statement is an if statement that appears within the body of another if or else statement. This allows for more complex conditions and decision-making structures in a program. Here is the syntax and an example of a nested if statement in C

if (condition1) 

{


//--Statement 1 is executed if condition1 is true

    Statement1;

    if (condition2) 

   {

        //-- Statement2 is executed if both condition1 and condition2 are true

      Statement2;

    }

    

    //-- More code you can execute outside of if block

   }

 else 

{

    //-- Statement3 is executed if condition1 is false

     Statement3;

    

    if (condition3) 

  {

//--Statement 4 is executed if condition3 is true

         Statement4;

    } 

else

 {

        //-- Statement5 to be executed if both condition1 and Condition 3 are false.

        Statement5;

    }

    

    // More code you can execute within the outer else block

}

// Code  you can execute outside the if-else blocks


e) Conditional/Teenary Expression:-

syntax:-

Expression1?Expression2:Expression3;

  • a) Expression1: A boolean expression that is evaluated
  • b) Expression2: The value or expression2 to be returned if Expression1 is true.
  • c) Expression3: The value or expression3 to be returned if Expression1 is false.

In this example, the ternary expression (number >= 0) ? "positive" : "negative" checks if the number is greater than or equal to 0. If true, the expression evaluates to "positive"; otherwise, it evaluates to "negative".


f)Switch Statement:-

The switch statement in C provides a way to handle multiple cases based on the value of an expression.


Syntax:-


switch (expression)

{

    case value1:

        // Block of code to be executed if expression equals value1;

        break;

    case value2:

        // Block of code to be executed if expression equals  value2;

        break;

    // additional cases as needed

    default:

        // block of code to be executed if none of the cases match the expression;

}


a) expression: the variable or value that is being tested.

b) case value 1: The first case to check. If the expression equals value 1, the code within this case is executed.

c) break: Terminates the switch statement. If omitted, execution will continue to the next case without checking for further matches.

d) default: If none of the cases match, the default block's code is executed.


Example:-

#include <stdio.h>

#include <conio.h>

void main() {

    char grade;


    printf("Enter your grade: ");

    scanf("%c", &grade);


    switch (grade) {

        case 'A':

            printf("Excellent!\n");

            break;

        case 'B':

            printf("Good!\n");

            break;

        case 'C':

            printf("Satisfactory.\n");

            break;

        case 'D':

            printf("Needs Improvement.\n");

            break;

        default:

            printf("Invalid grade.\n");

    }

    getch();

}


a). The user is prompted to enter a grade ('A', 'B', 'C', 'D').

b). To check the value of grade, the program uses a switch statement.

c). Based on the value of grade, it executes the corresponding case block.

Note: The break statement is used to exit the switch statement after a case is executed. If the break is omitted, execution will continue to the next case.


2. Unconditional Statements:


a)Break Statement:-


It is used to terminate the loop.

The break statement is used to terminate the execution of the innermost loop (for, while, or do-while).


syntax:-


for (initialization; condition; alteration) {

    // Statement to be executed in each iteration

    if (condition_to_out of loop) {

        break; // Exit the loop prematurely

    }

}


b)Continue Statement:-

It is used to skip the number of terms.

In C programming, the continue statement is used to skip the rest of the code inside a loop for the current iteration and move on to the next iteration of the loop. It is typically used within loops (for, while, or do-while) to jump to the next iteration prematurely.


Syntax:-


for (initialization; condition; alteration)

{

    // block of code before the continue statement


    if (condition_to_skip)

{

        continue; // Skip the rest of the block of code in the current alteration and move to the next alteration

    }


    // code after the continue statement

}


when (condition_to_skip) is true  then it skip current alteration and move to next alteration.


c) goto Statement:-

It is used to jump the control from one statement to another.


Example:-

int i;

for(i=1; i<=10; i++)

{

if(i==5)

{

goto label1;

}

printf("%d\n",i);

}

printf("out of loop");

label1:

printf("Hello");


Result:-

1 

2

3

4

Hello


Conclusion:-

label: It is a user-defined identifier followed by a colon (:). The label is a target for thegoto statement, indicating the position in the code where control should be transferred.

Here we use label1 in the example instead of label.

3. Repetitive statement:-

Repetitive statements, also known as loops, are used to execute a block of code repeatedly as long as a certain condition is true. There are three main types of loops in the C language: for, while, and do-while. Each type serves different purposes but shares the common objective of repetitive execution.


a). For Loop:

The for loop is typically used when the number of iterations is known beforehand.


Steps to work for loop:

1. Intialization 

2.Condition

3. Body of loop

4. Alteration 


Syntax:-

for (initialization; condition; Alteration)

{

Body of the loop;

}


Example:-

int i;

for(i=1;i<=5;i++)

{

printf("%d",i);

}


Result:-

1

2

3

4

5


b)While Loop:-

The while loop is used when the number of iterations is not known beforehand, and the loop continues as long as a specified condition is true.


syntax:-

While(condition)

{

Body of loop;

}


Example:-

int i=1;

while(i<=5)

{

printf("%d\n",i);

i++;

}


Result:-

1

2

3

4

5


c)do-while loop:-

The do-while loop is similar to the while loop, but it ensures that the loop body is executed at least once before the condition is checked.


Syntax:-

do

{

Body of loop;

}

while(condition);



Example:-

int i=1;

do

{

printf("%d\n",i);

i++;

}

while(i<=5);



Result:-

1

2

3

4

5








S
Shubham Saini
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Break and Continue Statements Explained in Python with Examples
Dec 09, 2023
Understanding Variables in Python: A Complete Guide with Examples
Dec 09, 2023
Understanding Method Parameters in C#: A Complete Guide
Dec 09, 2023
If Else Statement
Dec 09, 2023
Previous in Python
Understanding Variables in Python: A Complete Guide with Examples
Next in Python
Introduction to Python Programming: A Beginner's Guide
Buy me a pizza

Comments

On this page

🎯

Interview Prep

Ace your Python interview with curated Q&As for all levels.

View Python Interview Q&As

More in Python

  • Realtime face detection aon web cam in Python using OpenCV 7476 views
  • FastAPI Tutorial: Building Modern APIs with Python for High … 72 views
  • Deep Dive into Modules and Packages in Python: Structure and… 70 views
  • Understanding Explicit and Implicit Type Conversion in Pytho… 69 views
  • Mastering Web Scraping with Python and BeautifulSoup: A Comp… 66 views
View all Python posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1770
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • ASP.NET MVC
  • ASP.NET Web Forms
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • General Web Development
  • HTML, CSS
  • HTML/CSS
  • Java
  • JavaScript
  • JavaScript, HTML, CSS
  • JavaScript, Node.js
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor