SlideShare uma empresa Scribd logo
1 de 12
Conditional Branching Statements
Anoop K. C.
anoop@baabte.com
www.facebook.com/anoopbaabte
twitter.com/anoop_baabte
in.linkedin.com/in/anoopbaabte/
+91 9746854752
conditional statements allow us to take logical decisions about executing different
block of program to achieve the required logical output.
For example, conditional branching statements allow us to write logic such as, "If
you are over 25 years old, then you may rent a car.“
Here ”If you are over 25 years old” is a conditional statement which evaluates to
true or false
and ”you may rent a car” is the logic which has to be executed if the conditional
expression evaluates to true
There are two types of conditional branching statements in C#
The “if” statement
The “switch” statement
The “if” statement
The basic structure of the if statement is as follows
If (conditional statement)
{
//statements to execute
}
The statement inside the braces will execute if and only if the conditional
statement evaluates to true.
if we are using a series of mutually exclusive conditional statements we will use
the “if else” statement
The “if else” statement
Consider code snippet 1 and then code snippet 2
Both 1 and 2 does the same thing and output the same thing under identical
inputs
The “if else” statement - continued
But in the first code snippet , even when the first statement (number == 1)
evaluates to true, the compiler checks the other statements which is an unwanted
overhead which can affect the performance adversely.
But in the second code, since the first statement (number == 1) evaluates to true
the compiler ignores the next three “if” blocks.
if an expression in an if else statement evaluates to true, the compiler ignores the
following statements in that particular “if else block” and jumps to the line after
the “if else” statement.
We can also add an optional else statement at the end so that if none of the
conditions in the if, else if statements have been met, the code inside the else
block will be executed
We can also use conditional operators (and/or) in if statements in scenarios where
multiple expressions are to be evaluated to execute a code block.
The “switch” statement
After each code block a break statement is needed to go out of the switch
statement if the condition has been met and the corresponding code has been
executed
With a switch statement we can replace multiple if else statements.
The “switch” statement – contind.
We can also join multiple case statements inside a switch statements as shown in
the following code
The “goto” statement
The goto statement is used to shift the control of execution to any part of a
program marked with the label that succeeds the goto keyword.
The “goto” statement - continued
In the previous example, if the user enters an invalid entry, the program control
goes to the label marked as “start” and starts to execute the program from there ,
so that the program again prompts the user to enter a number between 1 and 5.
The scope of the goto statement is confined to the function in which it is defined
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Mais conteúdo relacionado

Mais procurados

Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
Jeya Lakshmi
 

Mais procurados (20)

Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptx
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings
StringsStrings
Strings
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Java Array String
Java Array StringJava Array String
Java Array String
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Strings
StringsStrings
Strings
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 

Semelhante a C# conditional branching statement

Semelhante a C# conditional branching statement (20)

Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
All about decision making statements in php
All about decision making statements in phpAll about decision making statements in php
All about decision making statements in php
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
4. decision making and some basic problem
4. decision making and some basic problem4. decision making and some basic problem
4. decision making and some basic problem
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 

Mais de baabtra.com - No. 1 supplier of quality freshers

Mais de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Último

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Último (20)

WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

C# conditional branching statement

  • 1.
  • 2. Conditional Branching Statements Anoop K. C. anoop@baabte.com www.facebook.com/anoopbaabte twitter.com/anoop_baabte in.linkedin.com/in/anoopbaabte/ +91 9746854752
  • 3. conditional statements allow us to take logical decisions about executing different block of program to achieve the required logical output. For example, conditional branching statements allow us to write logic such as, "If you are over 25 years old, then you may rent a car.“ Here ”If you are over 25 years old” is a conditional statement which evaluates to true or false and ”you may rent a car” is the logic which has to be executed if the conditional expression evaluates to true There are two types of conditional branching statements in C# The “if” statement The “switch” statement
  • 4. The “if” statement The basic structure of the if statement is as follows If (conditional statement) { //statements to execute } The statement inside the braces will execute if and only if the conditional statement evaluates to true. if we are using a series of mutually exclusive conditional statements we will use the “if else” statement
  • 5. The “if else” statement Consider code snippet 1 and then code snippet 2 Both 1 and 2 does the same thing and output the same thing under identical inputs
  • 6. The “if else” statement - continued But in the first code snippet , even when the first statement (number == 1) evaluates to true, the compiler checks the other statements which is an unwanted overhead which can affect the performance adversely. But in the second code, since the first statement (number == 1) evaluates to true the compiler ignores the next three “if” blocks. if an expression in an if else statement evaluates to true, the compiler ignores the following statements in that particular “if else block” and jumps to the line after the “if else” statement. We can also add an optional else statement at the end so that if none of the conditions in the if, else if statements have been met, the code inside the else block will be executed We can also use conditional operators (and/or) in if statements in scenarios where multiple expressions are to be evaluated to execute a code block.
  • 7. The “switch” statement After each code block a break statement is needed to go out of the switch statement if the condition has been met and the corresponding code has been executed With a switch statement we can replace multiple if else statements.
  • 8. The “switch” statement – contind. We can also join multiple case statements inside a switch statements as shown in the following code
  • 9. The “goto” statement The goto statement is used to shift the control of execution to any part of a program marked with the label that succeeds the goto keyword.
  • 10. The “goto” statement - continued In the previous example, if the user enters an invalid entry, the program control goes to the label marked as “start” and starts to execute the program from there , so that the program again prompts the user to enter a number between 1 and 5. The scope of the goto statement is confined to the function in which it is defined
  • 11. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 12. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com