SlideShare una empresa de Scribd logo
1 de 9
C# IF ELSE STATEMENTS
The conditional statement if.. else in C# is using for check the conditions that we
provided in the head of if statement and making decision based on that condition.
The conditional statement examining the data using comparison operators as well as
logical operators. The else statement is optional , so we can use the statement in two
ways ;
if (condition)
{
statement;
}
else if (condition)
{
statement;
}
else
{
statement;
}
if (condition)
{
statement;
}
if (condition)
{
statement;
}
else
{
statement;
}
switch(expression)
{
case value1:
statement;
break;
case value2:
statement;
break;
......
default:
statement;
}
The switch statement is used in C# to execute one code
from multiple expressions
SWITCH STATEMENT
Note: default code to be executed if above values are not matched.
Note: in switch statement all the cases will be evaluated if we do not
use break statement.
int a;
a = Convert.ToInt16(textBox1.Text);
if(a >=50)
{
textBox3.Text = “PASS”;
}
else {
textBox3.Text = “Fail”;
}
EXAMPLE 1
Using if statement to check if the student are passed or
failed
int a;
a =Convert.ToInt16 (textBox1.Text);
if(a<50)
{ textBox2.Text = "Fail"; }
else if (a >= 50&& a<60)
{ textBox2.Text = "Pass"; }
else if (a >= 60 && a < 70)
{ textBox2.Text = "Fair"; }
else if (a >= 70 && a < 80)
{ textBox2.Text = "Good"; }
else if (a >= 80 && a < 90)
{ textBox2.Text = "Vary Good";}
else if (a >= 90 && a <= 100)
{ textBox2.Text = "Excellent"; }
Using if statement for evaluation of Grades
EXAMPLE 2
int a, b, c=0;
string op;
a = Convert.ToInt16(textBox1.Text);
b = Convert.ToInt16(textBox2.Text);
op = comboBox1.Text;
if(op =="+")
{c = a + b;}
else if(op =="-")
{ c = a - b;}
else if(op ==“/")
{ c = a / b;}
else if(op =="*")
{ c = a * b;}
else {MessageBox.Show("please select an operation");}
textBox3.Text = Convert.ToString(c);
EXAMPLE 3
Using if statement for evaluation of mathematical
expression
Note: Select operation from combobox
int a, b, c=0;
string op;
a = Convert.ToInt16(textBox1.Text);
b = Convert.ToInt16(textBox2.Text);
op = comboBox1.Text;
switch (op)
{ case "+":
{ c = a + b;
break; }
case "-":
{ c = a - b;
break; }
case "/":
{ c = a / b;
break; }
case "*":
{c = a * b;
break;}
default:
{MessageBox.Show("please select an operation");
break;}
} textBox3.Text = Convert.ToString(c);
EXAMPLE 4
Using switch case statement for evaluation of mathematical expression
Note: Select operation from combobox
int day;
day =Convert.ToInt16 (textBox1.Text);
switch (day)
{
case 1: textBox2.Text = "Sunday";
break;
case 2: textBox2.Text = "Monday";
break;
case 3: textBox2.Text = "Tuesday";
break;
case 4: textBox2.Text = "Wednesday";
break;
case 5: textBox2.Text = "Thursday";
break;
case 6: textBox2.Text = "Friday";
break;
case 7: textBox2.Text = "Saturday";
break;
default: textBox2.Text = "Enter valid number";
break;
}
EXAMPLE 5

Más contenido relacionado

La actualidad más candente

Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 

La actualidad más candente (20)

Control structure
Control structureControl structure
Control structure
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
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
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Control statement
Control statementControl statement
Control statement
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
 

Similar a Vs c# lecture7

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
yasir_cesc
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
IIUM
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
alish sha
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
TAlha MAlik
 
ch4_additional.ppt
ch4_additional.pptch4_additional.ppt
ch4_additional.ppt
LokeshK66
 

Similar a Vs c# lecture7 (20)

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
C statements
C statementsC statements
C statements
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control All
Control AllControl All
Control All
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Switch.pptx
Switch.pptxSwitch.pptx
Switch.pptx
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Programming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-ExpressionsProgramming in java - Concepts- Operators- Control statements-Expressions
Programming in java - Concepts- Operators- Control statements-Expressions
 
Ch05.pdf
Ch05.pdfCh05.pdf
Ch05.pdf
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
ch4_additional.ppt
ch4_additional.pptch4_additional.ppt
ch4_additional.ppt
 
Branching
BranchingBranching
Branching
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 

Más de Saman M. Almufti

Más de Saman M. Almufti (20)

Lecture 7- domain name
Lecture  7- domain nameLecture  7- domain name
Lecture 7- domain name
 
Vp lecture 11 ararat
Vp lecture 11 araratVp lecture 11 ararat
Vp lecture 11 ararat
 
Vp lecture 10 ararat
Vp lecture 10 araratVp lecture 10 ararat
Vp lecture 10 ararat
 
Vp lecture 12 ararat
Vp lecture 12 araratVp lecture 12 ararat
Vp lecture 12 ararat
 
Vp lecture 9 ararat
Vp lecture 9 araratVp lecture 9 ararat
Vp lecture 9 ararat
 
Lecture 6- http
Lecture  6- httpLecture  6- http
Lecture 6- http
 
Lecture 5- url-dns
Lecture  5- url-dnsLecture  5- url-dns
Lecture 5- url-dns
 
Vp lecture 7 ararat
Vp lecture 7 araratVp lecture 7 ararat
Vp lecture 7 ararat
 
Lecture 4- ip
Lecture  4- ipLecture  4- ip
Lecture 4- ip
 
Vp lecture 6 ararat
Vp lecture 6 araratVp lecture 6 ararat
Vp lecture 6 ararat
 
Vp lecture 5 ararat
Vp lecture 5 araratVp lecture 5 ararat
Vp lecture 5 ararat
 
Lecture 3- tcp-ip
Lecture  3- tcp-ipLecture  3- tcp-ip
Lecture 3- tcp-ip
 
Vp lecture 4 ararat
Vp lecture 4 araratVp lecture 4 ararat
Vp lecture 4 ararat
 
Vp lecture 3 ararat
Vp lecture 3 araratVp lecture 3 ararat
Vp lecture 3 ararat
 
Lecture 2- terminology
Lecture  2- terminologyLecture  2- terminology
Lecture 2- terminology
 
Vp lecture 2 ararat
Vp lecture 2 araratVp lecture 2 ararat
Vp lecture 2 ararat
 
Vp lecture1 ararat
Vp lecture1 araratVp lecture1 ararat
Vp lecture1 ararat
 
Lecture 1- introduction
Lecture  1- introductionLecture  1- introduction
Lecture 1- introduction
 
Vs c# lecture12
Vs c# lecture12Vs c# lecture12
Vs c# lecture12
 
Vs c# lecture11
Vs c# lecture11Vs c# lecture11
Vs c# lecture11
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

Vs c# lecture7

  • 1.
  • 2.
  • 3. C# IF ELSE STATEMENTS The conditional statement if.. else in C# is using for check the conditions that we provided in the head of if statement and making decision based on that condition. The conditional statement examining the data using comparison operators as well as logical operators. The else statement is optional , so we can use the statement in two ways ; if (condition) { statement; } else if (condition) { statement; } else { statement; } if (condition) { statement; } if (condition) { statement; } else { statement; }
  • 4. switch(expression) { case value1: statement; break; case value2: statement; break; ...... default: statement; } The switch statement is used in C# to execute one code from multiple expressions SWITCH STATEMENT Note: default code to be executed if above values are not matched. Note: in switch statement all the cases will be evaluated if we do not use break statement.
  • 5. int a; a = Convert.ToInt16(textBox1.Text); if(a >=50) { textBox3.Text = “PASS”; } else { textBox3.Text = “Fail”; } EXAMPLE 1 Using if statement to check if the student are passed or failed
  • 6. int a; a =Convert.ToInt16 (textBox1.Text); if(a<50) { textBox2.Text = "Fail"; } else if (a >= 50&& a<60) { textBox2.Text = "Pass"; } else if (a >= 60 && a < 70) { textBox2.Text = "Fair"; } else if (a >= 70 && a < 80) { textBox2.Text = "Good"; } else if (a >= 80 && a < 90) { textBox2.Text = "Vary Good";} else if (a >= 90 && a <= 100) { textBox2.Text = "Excellent"; } Using if statement for evaluation of Grades EXAMPLE 2
  • 7. int a, b, c=0; string op; a = Convert.ToInt16(textBox1.Text); b = Convert.ToInt16(textBox2.Text); op = comboBox1.Text; if(op =="+") {c = a + b;} else if(op =="-") { c = a - b;} else if(op ==“/") { c = a / b;} else if(op =="*") { c = a * b;} else {MessageBox.Show("please select an operation");} textBox3.Text = Convert.ToString(c); EXAMPLE 3 Using if statement for evaluation of mathematical expression Note: Select operation from combobox
  • 8. int a, b, c=0; string op; a = Convert.ToInt16(textBox1.Text); b = Convert.ToInt16(textBox2.Text); op = comboBox1.Text; switch (op) { case "+": { c = a + b; break; } case "-": { c = a - b; break; } case "/": { c = a / b; break; } case "*": {c = a * b; break;} default: {MessageBox.Show("please select an operation"); break;} } textBox3.Text = Convert.ToString(c); EXAMPLE 4 Using switch case statement for evaluation of mathematical expression Note: Select operation from combobox
  • 9. int day; day =Convert.ToInt16 (textBox1.Text); switch (day) { case 1: textBox2.Text = "Sunday"; break; case 2: textBox2.Text = "Monday"; break; case 3: textBox2.Text = "Tuesday"; break; case 4: textBox2.Text = "Wednesday"; break; case 5: textBox2.Text = "Thursday"; break; case 6: textBox2.Text = "Friday"; break; case 7: textBox2.Text = "Saturday"; break; default: textBox2.Text = "Enter valid number"; break; } EXAMPLE 5