SlideShare una empresa de Scribd logo
1 de 12
Prepared by: Mrs. Nurul Zakiah Binti Zamri Tan
CONTROL
STATEMENT
TYPE OF CONTROL STATEMENT
C support 3 kinds of control structure:
sequential
selective
iterative
statement that is used to alter the
continuous sequential execution of
statements
sequential
no branching, looping or have any
decision making in the statement
A series of coding.
Source code is execute one after and after.
CONTROL STATEMENT ??
Use to control the flow of the source code/programming
Key to write a structured program where CS can :
Reduce complexity
Improve clarity.
Facilitate debugging and modifying
Technique to organize a program
Operation is simple to trace
ADVATAGES OF CONTROL STATEMENT
Structures are easier to define in flowcharts
Structure programming increases programmer's
productivity
CONTROL STATEMENT
Simple if statement
If else statement
If-else if ladder statement
Switch case statement
go to statement for statement
While statement
do-while
Unconditional Conditional Looping
If statement
If (test condition)
{
Statement block;
}
Next statement;
GENERAL FORM
#include <stdio.h>
#include <conio.h>
int main (void)
{
int num1;
int num2;
printf (“Please Enter 2 numbers”);
scanf(“%d%d”, &num1,&num2);
If (num1== num2)
{
printf(“There are equal”);
}
getch();
}
EXAMPLE
To execute one statement or
group of statements for
particular condition
If –else-statement
If (test condition)
{
Statement block-1;
}
else
{
Statement block-2
}
Next statement;
GENERAL FORM
#include <stdio.h>
void main()
{
int mark;
printf (“Please Enter mark”);
scanf( “%d”, &mark);
If (mark=>39)
{
printf(“Pass”);
}
else
{
printf(“Fail”);
}
getch();
}
EXAMPLE
To execute one group of
statements if the test condition is
true or other group if the test
condition is false
If else.. ladder statement
If (test condition-1)
{
Statement block-1;
}
Else if (test condition-2)
{
Statement block-2;
}
…
…
Else if (test condition-n)
{
Statement block-n;
}
Else
Default statement;
Next statement;
GENERAL FORM
To take multiple decision. This
statement is form by joining
if..else statement.
If one condition is false, it
checks for the next condition
and so on. When all the
conditions are false, then else
block is executed
#include<stdio.h>
#include<string.h>
void main()
{
int n;
printf(" Enter 1 to 3 to select your pet");
scanf("%d",&n);
if(n==1)
{
printf("You pet is a tiger");
}
else if(n==2)
{
printf("You pet is a sugar glider");
}
else if(n==3)
{
printf("You pet is a cow");
}
else
{
printf("No pet selected"); }
getch();
}
EXAMPLE
If else.. ladder statement
switch statement
switch (expression)
{
case value1:
Statement block-1:
break;
case value2:
Statement block-2:
break;
…
.. .
case value-n:
statement block-n:
break;
default:
default statement;
break;
}
Next statement
GENERAL FORM
Alternative to if else if ..ladder
statement
to execute a block of code
based on selection from multiple
choices.
C switch statement is a multiway
decisions that tests whether a
variable or expression matches
one of a number of constant
integer values, and branches
accordingly.
'break' is a statement. It is most
commonly used with the switch
statement. 'break' statement
stops the execution within the
switch statement and exits from
the switch statement.
#include <stdio.h>
main()
{
int Grade;
choose:
printf(“Please insert your grade A, B, C, D, E,
or F”);
scanf("%d",&Grade);
switch( Grade )
{
case 'A' :
printf( "Excellentn" );
break;
case 'B' :
printf( "Goodn" );
break;
case 'C' :
printf( "OKn" );
break;
EXAMPLE
case 'D' :
printf( "Mmmmm....n" );
break;
case 'F' :
printf( "You must do better than
thisn" );
break;
default :
printf( "What is your grade anyway?n"
); go to choose; break;
}
getch();
}
goto statement
goto label:
GENERAL FORM
Used to transfer the program
control unconditionally from one
point to another
its functionality is limited and it is only
recommended as a last resort if structured
solutions are much more complicated

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

File in C language
File in C languageFile in C language
File in C language
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
C pointer
C pointerC pointer
C pointer
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
C if else
C if elseC if else
C if else
 
Type conversion
Type conversionType conversion
Type conversion
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Function template
Function templateFunction template
Function template
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
String functions in C
String functions in CString functions in C
String functions in C
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Enums in c
Enums in cEnums in c
Enums in c
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
C++ oop
C++ oopC++ oop
C++ oop
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 

Destacado

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
 
Override control system
Override control systemOverride control system
Override control systemAshvani Shukla
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C ProgrammingHimanshu Negi
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual BasicTushar Jain
 

Destacado (6)

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
 
Control statements
Control statementsControl statements
Control statements
 
Override control system
Override control systemOverride control system
Override control system
 
Loops in C
Loops in CLoops in C
Loops in C
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 

Similar a Control Flow in C Programming

2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.pptManojKhadilkar1
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptxssuserfb3c3e
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programmingnmahi96
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
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
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxSKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxLECO9
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxSmitaAparadh
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Abou Bakr Ashraf
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 

Similar a Control Flow in C Programming (20)

2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
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
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 

Último

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Último (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Control Flow in C Programming

  • 1. Prepared by: Mrs. Nurul Zakiah Binti Zamri Tan CONTROL STATEMENT
  • 2. TYPE OF CONTROL STATEMENT C support 3 kinds of control structure: sequential selective iterative
  • 3. statement that is used to alter the continuous sequential execution of statements sequential no branching, looping or have any decision making in the statement A series of coding. Source code is execute one after and after. CONTROL STATEMENT ?? Use to control the flow of the source code/programming Key to write a structured program where CS can : Reduce complexity Improve clarity. Facilitate debugging and modifying Technique to organize a program
  • 4. Operation is simple to trace ADVATAGES OF CONTROL STATEMENT Structures are easier to define in flowcharts Structure programming increases programmer's productivity
  • 5. CONTROL STATEMENT Simple if statement If else statement If-else if ladder statement Switch case statement go to statement for statement While statement do-while Unconditional Conditional Looping
  • 6. If statement If (test condition) { Statement block; } Next statement; GENERAL FORM #include <stdio.h> #include <conio.h> int main (void) { int num1; int num2; printf (“Please Enter 2 numbers”); scanf(“%d%d”, &num1,&num2); If (num1== num2) { printf(“There are equal”); } getch(); } EXAMPLE To execute one statement or group of statements for particular condition
  • 7. If –else-statement If (test condition) { Statement block-1; } else { Statement block-2 } Next statement; GENERAL FORM #include <stdio.h> void main() { int mark; printf (“Please Enter mark”); scanf( “%d”, &mark); If (mark=>39) { printf(“Pass”); } else { printf(“Fail”); } getch(); } EXAMPLE To execute one group of statements if the test condition is true or other group if the test condition is false
  • 8. If else.. ladder statement If (test condition-1) { Statement block-1; } Else if (test condition-2) { Statement block-2; } … … Else if (test condition-n) { Statement block-n; } Else Default statement; Next statement; GENERAL FORM To take multiple decision. This statement is form by joining if..else statement. If one condition is false, it checks for the next condition and so on. When all the conditions are false, then else block is executed
  • 9. #include<stdio.h> #include<string.h> void main() { int n; printf(" Enter 1 to 3 to select your pet"); scanf("%d",&n); if(n==1) { printf("You pet is a tiger"); } else if(n==2) { printf("You pet is a sugar glider"); } else if(n==3) { printf("You pet is a cow"); } else { printf("No pet selected"); } getch(); } EXAMPLE If else.. ladder statement
  • 10. switch statement switch (expression) { case value1: Statement block-1: break; case value2: Statement block-2: break; … .. . case value-n: statement block-n: break; default: default statement; break; } Next statement GENERAL FORM Alternative to if else if ..ladder statement to execute a block of code based on selection from multiple choices. C switch statement is a multiway decisions that tests whether a variable or expression matches one of a number of constant integer values, and branches accordingly. 'break' is a statement. It is most commonly used with the switch statement. 'break' statement stops the execution within the switch statement and exits from the switch statement.
  • 11. #include <stdio.h> main() { int Grade; choose: printf(“Please insert your grade A, B, C, D, E, or F”); scanf("%d",&Grade); switch( Grade ) { case 'A' : printf( "Excellentn" ); break; case 'B' : printf( "Goodn" ); break; case 'C' : printf( "OKn" ); break; EXAMPLE case 'D' : printf( "Mmmmm....n" ); break; case 'F' : printf( "You must do better than thisn" ); break; default : printf( "What is your grade anyway?n" ); go to choose; break; } getch(); }
  • 12. goto statement goto label: GENERAL FORM Used to transfer the program control unconditionally from one point to another its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated