SlideShare ist ein Scribd-Unternehmen logo
1 von 10
CONTROL CONSTRUCTS
Control Constructs
Control constructs are of two types
1. DECISION MAKING STATEMENTS
2.LOOPING STATEMENTS
Control constructs are
Decision making statements
1. If statement
2.If else statement
3. Nested if else statement
4.Switch case
Looping statements
5.For loop
6.While loop
7.Do while loop
If statement:
if (condition)
statement;
or
if (condition)
{
compound statement;
}
Example of if statement:
int i;
printf ("Type in an integer");
scanf ("%ld", &i);
if (i == 0)
{
printf ("The number was zero");
}
if (i > 0)
{
printf ("The number was positive");
}
if (i < 0)
{
printf ("The number was negative");
}
If else statement:
if (condition)
statement1;
Else
statement2;
Or
if (condition)
{
statements1 ;
}
Else
{
statements2 ;
}
If - else
? else
if
Example of if-else statement:
int i;
scanf ("%d",i);
if (i > 0)
{
printf ("That number was positive!");
}
else
{
printf ("That number was negative or zero!");
}
Nested if else
statement:
if ((cond.) && (cond.))
{
statement;
}
OR
if (cond.)
{
if (cond.)
{
statement;
}
}
Example of nested-if statement:
if ((i > 2) && (i < 4))
{
printf ("i is three");
}
or:
if (i > 2)
{
if (i < 4)
{
printf ("i is three");
}
}
SWITCH & BREAK
switch (integer value)
{
case 1: statement1;
break;
/* optional line */
case 2: statement2;
break;
/* optional line */
....
default: default
statement
break;
/* optional line */
}
Switch case statement:

Weitere ähnliche Inhalte

Was ist angesagt?

Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c languagesneha2494
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C ProgrammingDevoAjit Gupta
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programmingprogramming9
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 

Was ist angesagt? (20)

Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
structure and union
structure and unionstructure and union
structure and union
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Loops in c
Loops in cLoops in c
Loops in c
 
Data types in C
Data types in CData types in C
Data types in C
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 

Ähnlich wie Branching in C

programming c language.
programming c language. programming c language.
programming c language. Abdul Rehman
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderMoni Adhikary
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structuresnikshaikh786
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdfRanjeetaSharma8
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)Jyoti Bhardwaj
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdfArkSingh7
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & ElseAbdullah Bhojani
 

Ähnlich wie Branching in C (20)

programming c language.
programming c language. programming c language.
programming c language.
 
Control statement
Control statementControl statement
Control statement
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladder
 
SPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in CSPL 7 | Conditional Statements in C
SPL 7 | Conditional Statements in C
 
Selection structure
Selection structureSelection structure
Selection structure
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Decision Making.pptx
Decision Making.pptxDecision Making.pptx
Decision Making.pptx
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf
 
control statement
control statement control statement
control statement
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
 

Mehr von Prabhu Govind (20)

Preprocessor in C
Preprocessor in CPreprocessor in C
Preprocessor in C
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
File in c
File in cFile in c
File in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Unions in c
Unions in cUnions in c
Unions in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
Array & string
Array & stringArray & string
Array & string
 
Recursive For S-Teacher
Recursive For S-TeacherRecursive For S-Teacher
Recursive For S-Teacher
 
User defined Functions in C
User defined Functions in CUser defined Functions in C
User defined Functions in C
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
 
Looping in C
Looping in CLooping in C
Looping in C
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
Operators in C
Operators in COperators in C
Operators in C
 
Statements in C
Statements in CStatements in C
Statements in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Constants in C
Constants in CConstants in C
Constants in C
 
Variables_c
Variables_cVariables_c
Variables_c
 
Tokens_C
Tokens_CTokens_C
Tokens_C
 
Computer basics
Computer basicsComputer basics
Computer basics
 
Computer fundamentals
Computer fundamentalsComputer fundamentals
Computer fundamentals
 

Kürzlich hochgeladen

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Branching in C

  • 2. Control Constructs Control constructs are of two types 1. DECISION MAKING STATEMENTS 2.LOOPING STATEMENTS
  • 3. Control constructs are Decision making statements 1. If statement 2.If else statement 3. Nested if else statement 4.Switch case Looping statements 5.For loop 6.While loop 7.Do while loop
  • 4. If statement: if (condition) statement; or if (condition) { compound statement; }
  • 5. Example of if statement: int i; printf ("Type in an integer"); scanf ("%ld", &i); if (i == 0) { printf ("The number was zero"); } if (i > 0) { printf ("The number was positive"); } if (i < 0) { printf ("The number was negative"); }
  • 6. If else statement: if (condition) statement1; Else statement2; Or if (condition) { statements1 ; } Else { statements2 ; } If - else ? else if
  • 7. Example of if-else statement: int i; scanf ("%d",i); if (i > 0) { printf ("That number was positive!"); } else { printf ("That number was negative or zero!"); }
  • 8. Nested if else statement: if ((cond.) && (cond.)) { statement; } OR if (cond.) { if (cond.) { statement; } }
  • 9. Example of nested-if statement: if ((i > 2) && (i < 4)) { printf ("i is three"); } or: if (i > 2) { if (i < 4) { printf ("i is three"); } }
  • 10. SWITCH & BREAK switch (integer value) { case 1: statement1; break; /* optional line */ case 2: statement2; break; /* optional line */ .... default: default statement break; /* optional line */ } Switch case statement: