SlideShare a Scribd company logo
1 of 15
VB.NET:- Decision Statements
BCA -501
2
Content
īƒ˜ Introduction
īƒ˜ If-Then Statement
īƒ˜ If-Then Else Statement
īƒ˜ If-Then ElseIf Statement
īƒ˜ Select Case Statement
īƒ˜ Nested Select Case Statements
3
What is Decision Statement?
īƒ˜ Decision making structures require that the programmer specify one or more
conditions to be evaluated or tested by the program, along with a statement or
statements to be executed if the condition is determined to be true, and optionally,
other statements to be executed if the condition is determined to be false.
īƒ˜ It is also known as Control Statements
īƒ˜ It is useful for determining whether a condition is true or not. If the condition is true,
a single or block of statement is executed.
īƒ˜ In the control statement, we will use if- Then, if Then Else, if Then ElseIf and
the Select case statement.
4
What is Decision Statement?
īƒ˜ Whenever an action has to be taken based on the outcome of a condition, decision
construct comes into picture.
īƒ˜ VB.NET supports decision constructs in the form of:
1. If..End If statements
2. If..Elseâ€ĻEndif Statements
3. Nested If Statements
4. Select Case â€Ļ End Case statement
5. Nested Select Case
5
If-Statement
The If-Then Statement is a control
statement that defines one or more
conditions, and if the particular condition
is satisfied, it executes a piece of
information or statements.
If condition Then
[Statement or block of Statement]
End If
The Then keyword is optional.
6
Example If-Statement
Module decisions
Sub Main()
'local variable definition '
Dim a As Integer = 100
' check the boolean condition using if statement
If (a < 20) Then
' if condition is true then print the following
Console.WriteLine("a is less than 20")
Else
' if condition is false then print the following
Console.WriteLine("a is not less than 20")
End If
Console.WriteLine("value of a is : {0}", a)
Console.ReadLine()
End Sub
End Module
7
Ifâ€ĻEles If-Statement
īƒ˜ An If statement can be followed by an optional Else if...Else statement, which is very useful
to test various conditions using single If...Else If statement.
īƒ˜ When using If... Else If... Else statements, there are few points to keep in mind.
1. An If can have zero or one Else's and it must come after an Else If's.
2. An If can have zero to many Else If's and they must come before the Else.
3. Once an Else if succeeds, none of the remaining Else If's or Else's will be tested.
Syntax: If(boolean_expression 1)Then
' Executes when the boolean expression 1 is true
ElseIf( boolean_expression 2)Then
' Executes when the boolean expression 2 is true
ElseIf( boolean_expression 3)Then
' Executes when the boolean expression 3 is true
Else
' executes when the none of the above condition is
true
End If
8
Example Ifâ€ĻElse IF-Statement
Module decisions
Sub Main()
'local variable definition '
Dim a As Integer = 100
' check the boolean condition '
If (a = 10) Then
' if condition is true then print the following '
Console.WriteLine("Value of a is 10") '
ElseIf (a = 20) Then
'if else if condition is true '
Console.WriteLine("Value of a is 20") '
ElseIf (a = 30) Then
'if else if condition is true
Console.WriteLine("Value of a is 30")
Else
'if none of the conditions is true
Console.WriteLine("None of the values is
matching")
End If
Console.WriteLine("Exact value of a is: {0}", a)
Console.ReadLine() End Sub
End Module
9
Nested- If-Statement
īƒ˜ It is always legal in VB.Net to nest If-Then-Else statements, which means you can use one If
or ElseIf statement inside another If ElseIf statement(s).
If( boolean_expression 1)Then
'Executes when the boolean expression 1 is true
If(boolean_expression 2)Then
'Executes when the boolean expression 2 is true
End If
End If
10
Example Ifâ€ĻElse IF-Statement
Module decisions
Sub Main()
'local variable definition
Dim a As Integer = 100
Dim b As Integer = 200
' check the boolean condition
If (a = 100) Then
' if condition is true then check the following
If (b = 200) Then
' if condition is true then print the following
Console.WriteLine("Value of a is 100 and b is 200")
End If
End If
Console.WriteLine("Exact value of a is : {0}", a)
Console.WriteLine("Exact value of b is : {0}", b)
Console.ReadLine()
End Sub
End Module
11
Select Caseâ€Ļ End Select-Statement
īƒ˜ Sometimes there may be too many conditions
to be evaluated and using Else If statements
may be cumbersome. In such situations it is
better to make use of Select.. Case.. End
Select
īƒ˜ A Select Case 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 select
case.
12
Select Caseâ€Ļ End Select-Statement
Select [ Case ] expression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
Where,
â€ĸexpression − is an expression that must evaluate to
any of the elementary data type in VB.Net, i.e.,
Boolean, Byte, Char, Date, Double, Decimal, Integer,
Long, Object, SByte, Short, Single, String, UInteger,
ULong, and UShort.
â€ĸexpressionlist − List of expression clauses
representing match values for expression. Multiple
expression clauses are separated by commas.
â€ĸstatements − statements following Case that run if the
select expression matches any clause in expressionlist.
â€ĸelsestatements − statements following Case Else that
run if the select expression does not match any clause
in the expressionlist of any of the Case statements
13
Example Select Case Statement
Module decisions
Sub Main()
'local variable definition
Dim grade As Char
grade = "B"
Select grade
Case "A"
Console.WriteLine("Excellent!")
Case "B", "C"
Console.WriteLine("Well done")
Case "D"
Console.WriteLine("You passed")
Case "F"
Console.WriteLine("Better try again")
Case Else
Console.WriteLine("Invalid grade")
End Select
Console.WriteLine("Your grade is {0}", grade)
Console.ReadLine()
End Sub
End Module
14
Nested Select Caseâ€Ļ End Select-Statement
īƒ˜ It is possible to have a select statement
as part of the statement sequence of an
outer select statement.
īƒ˜ Even if the case constants of the inner
and outer select contain common values,
no conflicts will arise
Module decisions
Sub Main()
'local variable definition
Dim a As Integer = 100
Dim b As Integer = 200
Select a ‘outer select case
Case 100
Console.WriteLine("This is part of outer case ")
Select Case b ‘inner select case
Case 200
Console.WriteLine("This is part of inner case
")
End Select
End Select
Console.WriteLine("Exact value of a is : {0}", a)
Console.WriteLine("Exact value of b is : {0}", b)
Console.ReadLine()
End Sub
End Module
15
Short-Circuited If Statements
īƒ˜ Given an If statement with two conditions, if the outcome can be determined without
evaluating each of the If conditions separately, it is called sjortcircuiting.
If x >y OR x > z
īƒ˜ Since an OR operator combines the two conditions, only one of the two conditions needs
to be True for the resultant outcome to be True. Hence it is not essential that the second
condition is evaluated once the First Conditions evaluated to True.
īƒ˜ Shortcircuiting if statements save time as there is no need to check both conditions.

More Related Content

What's hot

Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statementsFuture Programming
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#Dr.Neeraj Kumar Pandey
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...whileJayfee Ramos
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1Jomel Penalba
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
07 flow control
07   flow control07   flow control
07 flow controldhrubo kayal
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb scriptNilanjan Saha
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statementspragya ratan
 
Control structures i
Control structures i Control structures i
Control structures i Ahmad Idrees
 
Data structures vb
Data structures vbData structures vb
Data structures vbnicky_walters
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in javayugandhar vadlamudi
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Muhammad Tahir Bashir
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsIt Academy
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)Jyoti Bhardwaj
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-SharpAbid Kohistani
 
Control structure C++
Control structure C++Control structure C++
Control structure C++Anil Kumar
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 

What's hot (20)

Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
07 flow control
07   flow control07   flow control
07 flow control
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb script
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
 
Control structures i
Control structures i Control structures i
Control structures i
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)
 
Flow Control (C#)
Flow Control (C#)Flow Control (C#)
Flow Control (C#)
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-Sharp
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 

Similar to Decision statements

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
 
C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
If and select statement
If and select statementIf and select statement
If and select statementRahul Sharma
 
Conditional Statements & Loops
Conditional Statements & LoopsConditional Statements & Loops
Conditional Statements & Loopssimmis5
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingHossain Md Shakhawat
 
ch05.ppt
ch05.pptch05.ppt
ch05.pptNewsMogul
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional StatementsIntro C# Book
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection StatementsSzeChingChen
 
If and select statement
If and select statementIf and select statement
If and select statementRahul Sharma
 
Decision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsDecision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsPrabu U
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statementsmaznabili
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBclassall
 
conditional statements.docx
conditional statements.docxconditional statements.docx
conditional statements.docxssuser2e84e4
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control StatementAshim Lamichhane
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional StatementDeepak Singh
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 

Similar to Decision statements (20)

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
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Chapter 4 java
Chapter 4 javaChapter 4 java
Chapter 4 java
 
If and select statement
If and select statementIf and select statement
If and select statement
 
Conditional Statements & Loops
Conditional Statements & LoopsConditional Statements & Loops
Conditional Statements & Loops
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional Statements
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
If and select statement
If and select statementIf and select statement
If and select statement
 
Decision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsDecision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, Strings
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VB
 
conditional statements.docx
conditional statements.docxconditional statements.docx
conditional statements.docx
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional Statement
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 

More from Jaya Kumari

Python data type
Python data typePython data type
Python data typeJaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonJaya Kumari
 
Variables in python
Variables in pythonVariables in python
Variables in pythonJaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by pythonJaya Kumari
 
Inheritance
InheritanceInheritance
InheritanceJaya Kumari
 
Overloading
OverloadingOverloading
OverloadingJaya Kumari
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NETJaya Kumari
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netJaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netJaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespaceJaya Kumari
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net Jaya Kumari
 
Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xmlJaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script AdvanceJaya Kumari
 
Html Concept
Html ConceptHtml Concept
Html ConceptJaya Kumari
 

More from Jaya Kumari (18)

Python data type
Python data typePython data type
Python data type
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
 
Oops
OopsOops
Oops
 
Inheritance
InheritanceInheritance
Inheritance
 
Overloading
OverloadingOverloading
Overloading
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
 
Html form
Html formHtml form
Html form
 
Html Concept
Html ConceptHtml Concept
Html Concept
 

Recently uploaded

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
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
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
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

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
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
CÃŗdigo Creativo y Arte de Software | Unidad 1
CÃŗdigo Creativo y Arte de Software | Unidad 1CÃŗdigo Creativo y Arte de Software | Unidad 1
CÃŗdigo Creativo y Arte de Software | Unidad 1
 
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
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
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 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Decision statements

  • 2. 2 Content īƒ˜ Introduction īƒ˜ If-Then Statement īƒ˜ If-Then Else Statement īƒ˜ If-Then ElseIf Statement īƒ˜ Select Case Statement īƒ˜ Nested Select Case Statements
  • 3. 3 What is Decision Statement? īƒ˜ Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false. īƒ˜ It is also known as Control Statements īƒ˜ It is useful for determining whether a condition is true or not. If the condition is true, a single or block of statement is executed. īƒ˜ In the control statement, we will use if- Then, if Then Else, if Then ElseIf and the Select case statement.
  • 4. 4 What is Decision Statement? īƒ˜ Whenever an action has to be taken based on the outcome of a condition, decision construct comes into picture. īƒ˜ VB.NET supports decision constructs in the form of: 1. If..End If statements 2. If..Elseâ€ĻEndif Statements 3. Nested If Statements 4. Select Case â€Ļ End Case statement 5. Nested Select Case
  • 5. 5 If-Statement The If-Then Statement is a control statement that defines one or more conditions, and if the particular condition is satisfied, it executes a piece of information or statements. If condition Then [Statement or block of Statement] End If The Then keyword is optional.
  • 6. 6 Example If-Statement Module decisions Sub Main() 'local variable definition ' Dim a As Integer = 100 ' check the boolean condition using if statement If (a < 20) Then ' if condition is true then print the following Console.WriteLine("a is less than 20") Else ' if condition is false then print the following Console.WriteLine("a is not less than 20") End If Console.WriteLine("value of a is : {0}", a) Console.ReadLine() End Sub End Module
  • 7. 7 Ifâ€ĻEles If-Statement īƒ˜ An If statement can be followed by an optional Else if...Else statement, which is very useful to test various conditions using single If...Else If statement. īƒ˜ When using If... Else If... Else statements, there are few points to keep in mind. 1. An If can have zero or one Else's and it must come after an Else If's. 2. An If can have zero to many Else If's and they must come before the Else. 3. Once an Else if succeeds, none of the remaining Else If's or Else's will be tested. Syntax: If(boolean_expression 1)Then ' Executes when the boolean expression 1 is true ElseIf( boolean_expression 2)Then ' Executes when the boolean expression 2 is true ElseIf( boolean_expression 3)Then ' Executes when the boolean expression 3 is true Else ' executes when the none of the above condition is true End If
  • 8. 8 Example Ifâ€ĻElse IF-Statement Module decisions Sub Main() 'local variable definition ' Dim a As Integer = 100 ' check the boolean condition ' If (a = 10) Then ' if condition is true then print the following ' Console.WriteLine("Value of a is 10") ' ElseIf (a = 20) Then 'if else if condition is true ' Console.WriteLine("Value of a is 20") ' ElseIf (a = 30) Then 'if else if condition is true Console.WriteLine("Value of a is 30") Else 'if none of the conditions is true Console.WriteLine("None of the values is matching") End If Console.WriteLine("Exact value of a is: {0}", a) Console.ReadLine() End Sub End Module
  • 9. 9 Nested- If-Statement īƒ˜ It is always legal in VB.Net to nest If-Then-Else statements, which means you can use one If or ElseIf statement inside another If ElseIf statement(s). If( boolean_expression 1)Then 'Executes when the boolean expression 1 is true If(boolean_expression 2)Then 'Executes when the boolean expression 2 is true End If End If
  • 10. 10 Example Ifâ€ĻElse IF-Statement Module decisions Sub Main() 'local variable definition Dim a As Integer = 100 Dim b As Integer = 200 ' check the boolean condition If (a = 100) Then ' if condition is true then check the following If (b = 200) Then ' if condition is true then print the following Console.WriteLine("Value of a is 100 and b is 200") End If End If Console.WriteLine("Exact value of a is : {0}", a) Console.WriteLine("Exact value of b is : {0}", b) Console.ReadLine() End Sub End Module
  • 11. 11 Select Caseâ€Ļ End Select-Statement īƒ˜ Sometimes there may be too many conditions to be evaluated and using Else If statements may be cumbersome. In such situations it is better to make use of Select.. Case.. End Select īƒ˜ A Select Case 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 select case.
  • 12. 12 Select Caseâ€Ļ End Select-Statement Select [ Case ] expression [ Case expressionlist [ statements ] ] [ Case Else [ elsestatements ] ] End Select Where, â€ĸexpression − is an expression that must evaluate to any of the elementary data type in VB.Net, i.e., Boolean, Byte, Char, Date, Double, Decimal, Integer, Long, Object, SByte, Short, Single, String, UInteger, ULong, and UShort. â€ĸexpressionlist − List of expression clauses representing match values for expression. Multiple expression clauses are separated by commas. â€ĸstatements − statements following Case that run if the select expression matches any clause in expressionlist. â€ĸelsestatements − statements following Case Else that run if the select expression does not match any clause in the expressionlist of any of the Case statements
  • 13. 13 Example Select Case Statement Module decisions Sub Main() 'local variable definition Dim grade As Char grade = "B" Select grade Case "A" Console.WriteLine("Excellent!") Case "B", "C" Console.WriteLine("Well done") Case "D" Console.WriteLine("You passed") Case "F" Console.WriteLine("Better try again") Case Else Console.WriteLine("Invalid grade") End Select Console.WriteLine("Your grade is {0}", grade) Console.ReadLine() End Sub End Module
  • 14. 14 Nested Select Caseâ€Ļ End Select-Statement īƒ˜ It is possible to have a select statement as part of the statement sequence of an outer select statement. īƒ˜ Even if the case constants of the inner and outer select contain common values, no conflicts will arise Module decisions Sub Main() 'local variable definition Dim a As Integer = 100 Dim b As Integer = 200 Select a ‘outer select case Case 100 Console.WriteLine("This is part of outer case ") Select Case b ‘inner select case Case 200 Console.WriteLine("This is part of inner case ") End Select End Select Console.WriteLine("Exact value of a is : {0}", a) Console.WriteLine("Exact value of b is : {0}", b) Console.ReadLine() End Sub End Module
  • 15. 15 Short-Circuited If Statements īƒ˜ Given an If statement with two conditions, if the outcome can be determined without evaluating each of the If conditions separately, it is called sjortcircuiting. If x >y OR x > z īƒ˜ Since an OR operator combines the two conditions, only one of the two conditions needs to be True for the resultant outcome to be True. Hence it is not essential that the second condition is evaluated once the First Conditions evaluated to True. īƒ˜ Shortcircuiting if statements save time as there is no need to check both conditions.