SlideShare a Scribd company logo
1 of 21
PAPER NAME :CONDITIONAL
STATEMENTS.
STAFF :D.SARITHA
CLASS :I
SEMESTER :I
UNIT :I
TOPIC :PROGRAMMING IN
C
Conditional
statements
Forms of if statement
Simple if statement.
If…else statement.
Nested if…else statement.
Else .. if ladder.
IF STATEMENT
If statement is the decision making statement.
General form:
If (test expression)
{
statement – block;
}
statement-x;
IF STATEMENTS
EXAMPLE PROGRAM :
Main()
{
int a,b,c,d;
float ratio;
Printf(“Enter four integer valuesn”);
Scanf(“%d,%d,%d,%d”,&a,&b,&c,&d);
If(c-d !=0) /*execute statement block*/
{
ratio = (float)(a+b)/(float)(c-d);
printf(“ratio =%fn”,ratio);
}
}
OUTPUT:
Enter four integer values
12 23 34 45
ratio=-3.181818.
IF… ELSE STATEMENTS
If … else statement is the extension of if statement.
General form:
If (test expression)
{
//statement (s)
}
else
{
//statement(s)
}
IF ELSE STATEMENTS
EXAMPLE PROGRAM:
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d",&number);
// True if remainder is 0
if( number%2 == 0 )
printf("%d is an even integer.",number);
else
printf("%d is an odd integer.",number);
return 0;
}
IF ELSE STATEMENT
OUTPUT:
Enter an integer: 7
7 is an odd integer.
NESTED IF ELSE STATEMENT
The nested if else statement is that contains an if
else inside the body of the another if else
statements.
If the condition 1 is false the statement three will
be executed ;
Otherwise it contains to perform the second test .
If the condition 2 is true
GENERAL FORM:
if (testExpression1)
{
// statement(s)
}
else if(testExpression2)
{
// statement(s)
}
else if (testExpression 3)
{
// statement(s)
}
.
.
else
{
// statement(s)
}
NESTED IF ELSE STATEMENTS
include <stdio.h>
int main()
{
int number1, number2;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
if (number1 >= number2)
{
if (number1 == number2)
{
printf("Result: %d = %d",number1,number2);
}
NESTED IF ELSE STATEMENT
else
{
printf("Result: %d > %d", number1, number2);
}
}
else
{
printf("Result: %d < %d",number1, number2);
}
return 0;
}
NESTED IF ELSE STATEMENT
OUTPUT:
if (a > b) {
print("Hello");
}
print("Hi");
ELSE IF LADDER
The if...else statement execute two different
codes depending upon whether the test
expression is true or false. Sometimes a choice
has to be made from more than two possibility.
The if else ladder allows you to check for
multiple test expressions and execute various
statement(s).
ELSE IF LADDER
If(marks>79)
grade=“Honours”;
Else if(marks>59)
grade=“First division”;
Else if(marks>49)
grade=“second division”;
Else if(marks>39)
grade=“Third division”;
Else
grade+=“fail”;
Printf(“%s/n”,grade);
ELSE IF LADDER
OUTPUT:
fail.
SWITCH STATEMENT
A switch statement allows a variable to be
tested for equality against a list of values. Each
value is called a case, and the variable being
switched on is checked for each switch case.
SWITCH STATEMENT
switch(expression)
{
case value-1:
block-1;
break;
case value-2:
block-2;
break;
case value-3:
block-3;
break;
case value-4:
block-4;
break;
default:
default-block;
break;
}
SWITCH STATEMENT
int i = 1;
switch(i)
{
case 1:
printf("A"); // No break
case 2:
printf("B"); // No break
case 3:
printf("C");
break;
}
SWITCH STATEMENT
OUTPUT:
A B C

More Related Content

What's hot

C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal Acharya
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Decision making statements in C
Decision making statements in CDecision making statements in C
Decision making statements in CRabin BK
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2alish sha
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz |  PL SQL ExamplesPL SQL Quiz |  PL SQL Examples
PL SQL Quiz | PL SQL ExamplesShubham Dwivedi
 
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 Vishvesh Jasani
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & ElseAbdullah Bhojani
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements loopingMomenMostafa
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 

What's hot (20)

C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Decision making statements in C
Decision making statements in CDecision making statements in C
Decision making statements in C
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz |  PL SQL ExamplesPL SQL Quiz |  PL SQL Examples
PL SQL Quiz | PL SQL Examples
 
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
 
SQL MCQ
SQL MCQSQL MCQ
SQL MCQ
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Branching in C
Branching in CBranching in C
Branching in C
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 

Similar to Conditional statements

C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptSanjjaayyy
 
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
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfmounikanarra3
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programmingnmahi96
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptxDEEPAK948083
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If conditionyarkhosh
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in cyndaravind
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
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
 

Similar to Conditional statements (20)

Control statement
Control statementControl statement
Control statement
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
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
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
7 functions
7  functions7  functions
7 functions
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If condition
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in c
 
Branching statements
Branching statementsBranching statements
Branching statements
 
L3 control
L3 controlL3 control
L3 control
 
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
 

Recently uploaded

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
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
 

Recently uploaded (20)

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
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
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
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
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
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
 

Conditional statements

  • 1. PAPER NAME :CONDITIONAL STATEMENTS. STAFF :D.SARITHA CLASS :I SEMESTER :I UNIT :I TOPIC :PROGRAMMING IN C
  • 3. Forms of if statement Simple if statement. If…else statement. Nested if…else statement. Else .. if ladder.
  • 4. IF STATEMENT If statement is the decision making statement. General form: If (test expression) { statement – block; } statement-x;
  • 5. IF STATEMENTS EXAMPLE PROGRAM : Main() { int a,b,c,d; float ratio; Printf(“Enter four integer valuesn”); Scanf(“%d,%d,%d,%d”,&a,&b,&c,&d); If(c-d !=0) /*execute statement block*/ { ratio = (float)(a+b)/(float)(c-d); printf(“ratio =%fn”,ratio); } }
  • 6. OUTPUT: Enter four integer values 12 23 34 45 ratio=-3.181818.
  • 7. IF… ELSE STATEMENTS If … else statement is the extension of if statement. General form: If (test expression) { //statement (s) } else { //statement(s) }
  • 8. IF ELSE STATEMENTS EXAMPLE PROGRAM: #include <stdio.h> int main() { int number; printf("Enter an integer: "); scanf("%d",&number); // True if remainder is 0 if( number%2 == 0 ) printf("%d is an even integer.",number); else printf("%d is an odd integer.",number); return 0; }
  • 9. IF ELSE STATEMENT OUTPUT: Enter an integer: 7 7 is an odd integer.
  • 10. NESTED IF ELSE STATEMENT The nested if else statement is that contains an if else inside the body of the another if else statements. If the condition 1 is false the statement three will be executed ; Otherwise it contains to perform the second test . If the condition 2 is true
  • 11. GENERAL FORM: if (testExpression1) { // statement(s) } else if(testExpression2) { // statement(s) } else if (testExpression 3) { // statement(s) } . . else { // statement(s) }
  • 12. NESTED IF ELSE STATEMENTS include <stdio.h> int main() { int number1, number2; printf("Enter two integers: "); scanf("%d %d", &number1, &number2); if (number1 >= number2) { if (number1 == number2) { printf("Result: %d = %d",number1,number2); }
  • 13. NESTED IF ELSE STATEMENT else { printf("Result: %d > %d", number1, number2); } } else { printf("Result: %d < %d",number1, number2); } return 0; }
  • 14. NESTED IF ELSE STATEMENT OUTPUT: if (a > b) { print("Hello"); } print("Hi");
  • 15. ELSE IF LADDER The if...else statement execute two different codes depending upon whether the test expression is true or false. Sometimes a choice has to be made from more than two possibility. The if else ladder allows you to check for multiple test expressions and execute various statement(s).
  • 16. ELSE IF LADDER If(marks>79) grade=“Honours”; Else if(marks>59) grade=“First division”; Else if(marks>49) grade=“second division”; Else if(marks>39) grade=“Third division”; Else grade+=“fail”; Printf(“%s/n”,grade);
  • 18. SWITCH STATEMENT A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
  • 19. SWITCH STATEMENT switch(expression) { case value-1: block-1; break; case value-2: block-2; break; case value-3: block-3; break; case value-4: block-4; break; default: default-block; break; }
  • 20. SWITCH STATEMENT int i = 1; switch(i) { case 1: printf("A"); // No break case 2: printf("B"); // No break case 3: printf("C"); break; }