SlideShare a Scribd company logo
1 of 14
Selection Statements

      VB.NET



                       1
Objectives
Understand how relational operators are
used to create a condition
Understand and use IF
statements, including nested IF statements
Understand and use compound conditions
Develop and evaluate multiple solutions to
the same problem
Successfully write program solutions that
require decision making
                                             2
Selection Statements
The most common decision structure is the IF statement.
A condition is a boolean expression that evaluates to either
true or false.
Comparison operators require numeric operands and
produce a logical result.
Conditions typically involve one of six relational operators.
 Greater than             >
 Less than                <
 Greater than or equal    >=
 Less than or equal       <=
 Equal                    =
 Not equal                <>

                                                                3
The IF Statement Conditions




                              4
Simple IF Statements (design)


Decision symbol

                     Process symbol




                                      5
Solving the Overtime Problem




                               6
VB.net code Example
Private Sub btnCheck_Click()
        Dim Input, value1, value2 As Integer
        If Input = value1 Then         ‘ Condition 1 is True
                process A                     ‘so only this code runs
        ElseIf Input = value2 Then ‘ Condition 2 is True
                process B                     ‘different response
        Else                           ‘ Neither condition is True
                process C                     ‘can be error message
        End If
End Sub

   Task 1: Create programs to perform the functions shown
   in the flow chart examples.
   Task 2: Create a version(2) of the Correct Change
   program (from Input/Output) using selection statements.

                                                                        7
Nested IF Statements (design)
The term nested IF refers to
an IF statement contained
within the true or false
branch of another IF
statement.




                                8
True OR False Conditions




                           9
Compound Conditions
A compound condition consists of two
conditions within parentheses joined by a
logical operator.
Logical Operators require logical operands
and produce a logical result.
   NOT   Logical opposite
   AND   Both values are true
   OR    At least one value is true
   XOR   Exactly one value is true
                                             10
Logical Operators




                    11
Operator Precedence
When several operations occur in an
expression, each part is evaluated and
resolved in a predetermined order called
operator precedence.
 1st : Evaluate all arithmetic/concatenation
  operators
 2nd : Evaluate all comparison operators
 3rd : Evaluate all logical operators


                                                12
The Select…..Case Statement
When more choices are available use the
Select – Case statement, an example is
shown below.




                                          13
Summary
A condition is an expression that evaluates
to either true or false.
IF statements use conditions to choose
between actions.
The true and false branches of an IF
statement may contain any valid
statement, including other IF statements.
A compound condition is two or more
conditions joined by a logical operator.

                                              14

More Related Content

What's hot

Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in JavaNiloy Saha
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Syed Farjad Zia Zaidi
 
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 1Techglyphs
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
Conditional statements
Conditional statementsConditional statements
Conditional statementscherrybear2014
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityAakash Singh
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
10. switch case
10. switch case10. switch case
10. switch caseWay2itech
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Python PCEP Variables
Python PCEP VariablesPython PCEP Variables
Python PCEP VariablesIHTMINSTITUTE
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingDhrumil Panchal
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1Syed Farjad Zia Zaidi
 

What's hot (19)

Control structures ii
Control structures ii Control structures ii
Control structures ii
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Ppt lesson 08
Ppt lesson 08Ppt lesson 08
Ppt lesson 08
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
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
Control StructuresControl Structures
Control Structures
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
10. switch case
10. switch case10. switch case
10. switch case
 
Variables
VariablesVariables
Variables
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Python PCEP Variables
Python PCEP VariablesPython PCEP Variables
Python PCEP Variables
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 

Viewers also liked

Viewers also liked (20)

Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theory
 
Design for edp
Design for edpDesign for edp
Design for edp
 
Controls
ControlsControls
Controls
 
Using loops
Using loopsUsing loops
Using loops
 
Vb.net session 12
Vb.net session 12Vb.net session 12
Vb.net session 12
 
Vb net xp_11
Vb net xp_11Vb net xp_11
Vb net xp_11
 
Decisions
DecisionsDecisions
Decisions
 
Simple debugging
Simple debuggingSimple debugging
Simple debugging
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Software development lifecycle
Software development lifecycleSoftware development lifecycle
Software development lifecycle
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Design documentation
Design documentationDesign documentation
Design documentation
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Event driven programming amazeballs
Event driven programming amazeballsEvent driven programming amazeballs
Event driven programming amazeballs
 
Event oriented programming
Event oriented programmingEvent oriented programming
Event oriented programming
 
(WRK302) Event-Driven Programming
(WRK302) Event-Driven Programming(WRK302) Event-Driven Programming
(WRK302) Event-Driven Programming
 

Similar to VB.NET Selection Statements

Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a programYsa Castillo
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUjwala Junghare
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxEyasu46
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statementEyelean xilef
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statementEyelean xilef
 
3 chapter three - part 1.pdf
3 chapter three - part 1.pdf3 chapter three - part 1.pdf
3 chapter three - part 1.pdfAbenezerAsefa1
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selectionHamad Odhabi
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection StatementsSzeChingChen
 
Chapter 2 - Flow of Control Part I.pdf
Chapter 2 -  Flow of Control Part I.pdfChapter 2 -  Flow of Control Part I.pdf
Chapter 2 - Flow of Control Part I.pdfKirubelWondwoson1
 
Control structures i
Control structures i Control structures i
Control structures i Ahmad Idrees
 
Na50 enus devi_14
Na50 enus devi_14Na50 enus devi_14
Na50 enus devi_14thurmond
 
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 languageshhanks
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfBasic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfComputer Programmer
 

Similar to VB.NET Selection Statements (20)

Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a program
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
C sharp chap4
C sharp chap4C sharp chap4
C sharp chap4
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptx
 
Decision control
Decision controlDecision control
Decision control
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
3 chapter three - part 1.pdf
3 chapter three - part 1.pdf3 chapter three - part 1.pdf
3 chapter three - part 1.pdf
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
Chapter 2 - Flow of Control Part I.pdf
Chapter 2 -  Flow of Control Part I.pdfChapter 2 -  Flow of Control Part I.pdf
Chapter 2 - Flow of Control Part I.pdf
 
Control structures i
Control structures i Control structures i
Control structures i
 
Na50 enus devi_14
Na50 enus devi_14Na50 enus devi_14
Na50 enus devi_14
 
SDD Conditional Statements
SDD Conditional StatementsSDD Conditional Statements
SDD Conditional Statements
 
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
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfBasic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
 

More from nicky_walters

More from nicky_walters (7)

Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Event driventheory
Event driventheoryEvent driventheory
Event driventheory
 
Debugging
DebuggingDebugging
Debugging
 
Intro to visual studio 2008
Intro to visual studio 2008Intro to visual studio 2008
Intro to visual studio 2008
 
Input output
Input outputInput output
Input output
 

VB.NET Selection Statements

  • 2. Objectives Understand how relational operators are used to create a condition Understand and use IF statements, including nested IF statements Understand and use compound conditions Develop and evaluate multiple solutions to the same problem Successfully write program solutions that require decision making 2
  • 3. Selection Statements The most common decision structure is the IF statement. A condition is a boolean expression that evaluates to either true or false. Comparison operators require numeric operands and produce a logical result. Conditions typically involve one of six relational operators.  Greater than >  Less than <  Greater than or equal >=  Less than or equal <=  Equal =  Not equal <> 3
  • 4. The IF Statement Conditions 4
  • 5. Simple IF Statements (design) Decision symbol Process symbol 5
  • 7. VB.net code Example Private Sub btnCheck_Click() Dim Input, value1, value2 As Integer If Input = value1 Then ‘ Condition 1 is True process A ‘so only this code runs ElseIf Input = value2 Then ‘ Condition 2 is True process B ‘different response Else ‘ Neither condition is True process C ‘can be error message End If End Sub Task 1: Create programs to perform the functions shown in the flow chart examples. Task 2: Create a version(2) of the Correct Change program (from Input/Output) using selection statements. 7
  • 8. Nested IF Statements (design) The term nested IF refers to an IF statement contained within the true or false branch of another IF statement. 8
  • 9. True OR False Conditions 9
  • 10. Compound Conditions A compound condition consists of two conditions within parentheses joined by a logical operator. Logical Operators require logical operands and produce a logical result.  NOT Logical opposite  AND Both values are true  OR At least one value is true  XOR Exactly one value is true 10
  • 12. Operator Precedence When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence.  1st : Evaluate all arithmetic/concatenation operators  2nd : Evaluate all comparison operators  3rd : Evaluate all logical operators 12
  • 13. The Select…..Case Statement When more choices are available use the Select – Case statement, an example is shown below. 13
  • 14. Summary A condition is an expression that evaluates to either true or false. IF statements use conditions to choose between actions. The true and false branches of an IF statement may contain any valid statement, including other IF statements. A compound condition is two or more conditions joined by a logical operator. 14