SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Conditional Statement 
Prepared By :- Rahul Sharma 
Enrollment No. : 07521102013 
Subject :- VB .NET 
Faculty :- Mr. Neeraj Mishra
Selection or Condition Construct 
 The selection or decision construct means the 
execution of statement(s) depending upon the 
condition-test. 
 If a condition evaluates to True, a course-of-action (a 
set of statements) is followed otherwise another 
course-of-action is followed. 
 This construct is also called decision construct as it 
helps in decision making.
Selection or Condition Constructs 
 VB provides two types of selection construct : 
1. If statement 
2. Select Case statement 
 The If Statement : If statement of VB comes in 
various forms & are given below: 
1) If..Then Statement 
2) If..Then..Else Statement 
3) If..Then..ElseIf Statement 
4) Nested Ifs
If..Then Statement 
 Definition : An If..Then statement tests a particular 
condition; if the condition evaluates to true, a course-of-action 
is followed otherwise it is ignored. 
Syntax : 
If (boolean expression) Then 
statements 
End If 
Example : 
If txtAge.Text>=18 Then 
MsgBox(“You are eligible to vote”) 
End if
If..Then..Else Statement 
 If..Then..Else statement provides an alternate choice to the user 
i.e. if the condition is true then a set of statements are executed 
otherwise another set of statements are executed. 
Syntax : 
If (boolean Expression) Then 
VB Statement(s) 
Else 
VB Statement(s) 
End If 
Example : 
If (txtAge.Text>=18) Then 
MsgBox(“You are eligible to vote”) 
Else 
MsgBox(“Sorry, You are not eligible to vote”) 
End If
If..Then..ElseIf Statement 
 If..Then..ElseIf statement is used to test a number of mutually 
exclusive cases and only executes one set of statements for the case 
that is true first. 
Example: 
If (Age<=4) Then 
MsgBox(“Your rate is free.”) 
ElseIf (Age<=12) Then 
MsgBox(“You qualify for the children’s 
rate.”) 
ElseIf (Age<65) Then 
MsgBox(“You must pay full rate”) 
Else 
MsgBox(“You qualify for the seniors’ 
rate.”) 
End If 
Syntax : 
If (Boolean Expression) Then 
Statement(s) 
ElseIf (Boolean Expression 2) Then 
Statement(s) 
ElseIf (Boolean Expression 3) Then 
Statement(s) 
: 
Else 
Statement(s) 
End If
Nested Ifs 
 A nested If is an if that has another If in its if ’s body or in its 
else’s body. 
 The nested if can have one of the following 3 forms :- 
1. If (expression 1) Then 
If (expression 2 ) Then 
Statement 1 
Else 
Statement 2 
End If 
Else 
body-of-else 
End If 
2. If (expression 1) Then 
body-of-if 
Else 
: 
If (expression 2) Then 
Statement-1 
Else 
Statement-2 
End If
3. If (expression 1) Then 
: 
If (expression 2) Then 
Statement-1 
Else 
Statement-2 
End If 
Else 
If (expression 3) Then 
Statement-3 
Else 
Statement-4 
: 
End If 
End If 
Example of Nested If: 
If Num>0 Then 
Msgbox(“It is a positive number”) 
Else 
If Num<0 Then 
Msgbox(“It is a negative number”) 
Else 
Msgbox(“The number is equal to 
zero”) 
End If 
End If
Select-Case Statement 
 Select-Case is a multiple branching statement and is 
used to executed a set of statements depending upon 
the value of the expression. 
 It is better to use Select-Case statement in comparison 
to If..Then..ElseIf Statement when the number of 
checks are more. 
 There are 3 different forms of using Select-Case 
statements and are given below :
Different forms of Select-Case 
1. Select Case : Simplest Form [Exact match] 
Select Case Expression 
Case Value 
’visual basic statements 
Case Value 
’visual basic statements 
Case Else 
’visual basic statements 
End Select 
Example : 
Select Case byMonth 
Case 1,3,5,7,8,10,12 
number_of_days=31 
Case 2 
number_of_days=28 
Case Else 
number_of_days=30 
End Select
2.Select Case : Second Form [Relational Test] 
Select Case Expression 
Case Is relation 
’visual basic statements 
Case Is relation 
’visual basic statements 
Case Else 
’visual basic statements 
End Select 
Example: 
Select Case marks 
Case Is < 50 
Result = “Fail” 
Case Is < 60 
Result = “Grade B” 
Case Is < 75 
Result = “Grade A” 
Case Else 
Result = “Grade A+” 
End Select
3.Select Case : Third Format [Range Check] 
Select Case Expression 
Case exp1 To exp2: 
’visual basic statements 
Case exp1 To exp2: 
’visual basic statements 
Case Else: 
’visual basic statements 
End Select 
Example : 
Select Case Age 
Case 2 to 4 : Msgbox(“PreNursery”) 
Case 4 to 6 : Msgbox(“Kindergarden”) 
Case 6 to 10 : Msgbox(“Primary”) 
Case Else : Msgbox(“Others”) 
End Select
If and select statement

Weitere ähnliche Inhalte

Was ist angesagt?

c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04jabirMemon
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selectionHamad Odhabi
 
Python decision making part5
Python decision making part5Python decision making part5
Python decision making part5Vishal Dutt
 
Effective Java - Methods Common to All Objects
Effective Java - Methods Common to All ObjectsEffective Java - Methods Common to All Objects
Effective Java - Methods Common to All ObjectsRoshan Deniyage
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variablesPrem Kumar Badri
 
Effective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All ObjectsEffective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All Objectsİbrahim Kürce
 
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
 

Was ist angesagt? (14)

c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04c++ computer programming language datatypes ,operators,Lecture 03 04
c++ computer programming language datatypes ,operators,Lecture 03 04
 
MA3696 Lecture 7
MA3696 Lecture 7MA3696 Lecture 7
MA3696 Lecture 7
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 
Java -lec-3
Java -lec-3Java -lec-3
Java -lec-3
 
Python decision making part5
Python decision making part5Python decision making part5
Python decision making part5
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Effective Java - Methods Common to All Objects
Effective Java - Methods Common to All ObjectsEffective Java - Methods Common to All Objects
Effective Java - Methods Common to All Objects
 
Select case
Select caseSelect case
Select case
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Effective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All ObjectsEffective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All Objects
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
 
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
 
Ppt lesson 08
Ppt lesson 08Ppt lesson 08
Ppt lesson 08
 

Ähnlich wie If and select statement

If and select statement
If and select statementIf and select statement
If and select statementRahul Sharma
 
Decision statements
Decision statementsDecision statements
Decision statementsJaya Kumari
 
conditional statements.docx
conditional statements.docxconditional statements.docx
conditional statements.docxssuser2e84e4
 
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
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)Jyoti Bhardwaj
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
Programming (if else)
Programming (if else)Programming (if else)
Programming (if else)Papon Sarker
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBclassall
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankLauriewest24
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
Working with comparison operators
Working with comparison operatorsWorking with comparison operators
Working with comparison operatorsSara Corpuz
 

Ähnlich wie If and select statement (20)

If and select statement
If and select statementIf and select statement
If and select statement
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Decision statements
Decision statementsDecision statements
Decision statements
 
conditional statements.docx
conditional statements.docxconditional statements.docx
conditional statements.docx
 
Decision making
Decision makingDecision making
Decision making
 
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
 
Using decision statements
Using decision statementsUsing decision statements
Using decision statements
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Programming (if else)
Programming (if else)Programming (if else)
Programming (if else)
 
Ch05-converted.pptx
Ch05-converted.pptxCh05-converted.pptx
Ch05-converted.pptx
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VB
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Absolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test BankAbsolute Java 5e Savitch Test Bank
Absolute Java 5e Savitch Test Bank
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
Working with comparison operators
Working with comparison operatorsWorking with comparison operators
Working with comparison operators
 
If else statement 05 (js)
If else statement 05 (js)If else statement 05 (js)
If else statement 05 (js)
 

Mehr von Rahul Sharma

Introduction to computer networks & it’s usage
Introduction to computer networks & it’s usageIntroduction to computer networks & it’s usage
Introduction to computer networks & it’s usageRahul Sharma
 
Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template libraryRahul Sharma
 
System of book keeping
System of book keepingSystem of book keeping
System of book keepingRahul Sharma
 
Standard deviation
Standard deviationStandard deviation
Standard deviationRahul Sharma
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagramRahul Sharma
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingRahul Sharma
 
BLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
BLOCK DIAGRAM OF HARDWIRED CONTROL UNITBLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
BLOCK DIAGRAM OF HARDWIRED CONTROL UNITRahul Sharma
 
Accounting standards(as)
Accounting standards(as)Accounting standards(as)
Accounting standards(as)Rahul Sharma
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingRahul Sharma
 
Listeningskills 120213044302-phpapp01
Listeningskills 120213044302-phpapp01Listeningskills 120213044302-phpapp01
Listeningskills 120213044302-phpapp01Rahul Sharma
 
Stack 111104232459-phpapp02
Stack 111104232459-phpapp02Stack 111104232459-phpapp02
Stack 111104232459-phpapp02Rahul Sharma
 
Smart cards 07521102013
Smart cards 07521102013Smart cards 07521102013
Smart cards 07521102013Rahul Sharma
 
Data,information and database
Data,information and databaseData,information and database
Data,information and databaseRahul Sharma
 
Basic computer fundamentals
Basic computer fundamentalsBasic computer fundamentals
Basic computer fundamentalsRahul Sharma
 

Mehr von Rahul Sharma (19)

Introduction to computer networks & it’s usage
Introduction to computer networks & it’s usageIntroduction to computer networks & it’s usage
Introduction to computer networks & it’s usage
 
Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template library
 
System of book keeping
System of book keepingSystem of book keeping
System of book keeping
 
Standard deviation
Standard deviationStandard deviation
Standard deviation
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Depriciation
DepriciationDepriciation
Depriciation
 
BLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
BLOCK DIAGRAM OF HARDWIRED CONTROL UNITBLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
BLOCK DIAGRAM OF HARDWIRED CONTROL UNIT
 
Accounting standards(as)
Accounting standards(as)Accounting standards(as)
Accounting standards(as)
 
Listing skill
Listing skillListing skill
Listing skill
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Listeningskills 120213044302-phpapp01
Listeningskills 120213044302-phpapp01Listeningskills 120213044302-phpapp01
Listeningskills 120213044302-phpapp01
 
Euler’s formula
Euler’s formulaEuler’s formula
Euler’s formula
 
Stack 111104232459-phpapp02
Stack 111104232459-phpapp02Stack 111104232459-phpapp02
Stack 111104232459-phpapp02
 
Smart cards 07521102013
Smart cards 07521102013Smart cards 07521102013
Smart cards 07521102013
 
Data,information and database
Data,information and databaseData,information and database
Data,information and database
 
Array
ArrayArray
Array
 
Basic computer fundamentals
Basic computer fundamentalsBasic computer fundamentals
Basic computer fundamentals
 
Rolling friction
Rolling frictionRolling friction
Rolling friction
 

Kürzlich hochgeladen

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Kürzlich hochgeladen (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

If and select statement

  • 1. Conditional Statement Prepared By :- Rahul Sharma Enrollment No. : 07521102013 Subject :- VB .NET Faculty :- Mr. Neeraj Mishra
  • 2. Selection or Condition Construct  The selection or decision construct means the execution of statement(s) depending upon the condition-test.  If a condition evaluates to True, a course-of-action (a set of statements) is followed otherwise another course-of-action is followed.  This construct is also called decision construct as it helps in decision making.
  • 3. Selection or Condition Constructs  VB provides two types of selection construct : 1. If statement 2. Select Case statement  The If Statement : If statement of VB comes in various forms & are given below: 1) If..Then Statement 2) If..Then..Else Statement 3) If..Then..ElseIf Statement 4) Nested Ifs
  • 4. If..Then Statement  Definition : An If..Then statement tests a particular condition; if the condition evaluates to true, a course-of-action is followed otherwise it is ignored. Syntax : If (boolean expression) Then statements End If Example : If txtAge.Text>=18 Then MsgBox(“You are eligible to vote”) End if
  • 5. If..Then..Else Statement  If..Then..Else statement provides an alternate choice to the user i.e. if the condition is true then a set of statements are executed otherwise another set of statements are executed. Syntax : If (boolean Expression) Then VB Statement(s) Else VB Statement(s) End If Example : If (txtAge.Text>=18) Then MsgBox(“You are eligible to vote”) Else MsgBox(“Sorry, You are not eligible to vote”) End If
  • 6. If..Then..ElseIf Statement  If..Then..ElseIf statement is used to test a number of mutually exclusive cases and only executes one set of statements for the case that is true first. Example: If (Age<=4) Then MsgBox(“Your rate is free.”) ElseIf (Age<=12) Then MsgBox(“You qualify for the children’s rate.”) ElseIf (Age<65) Then MsgBox(“You must pay full rate”) Else MsgBox(“You qualify for the seniors’ rate.”) End If Syntax : If (Boolean Expression) Then Statement(s) ElseIf (Boolean Expression 2) Then Statement(s) ElseIf (Boolean Expression 3) Then Statement(s) : Else Statement(s) End If
  • 7. Nested Ifs  A nested If is an if that has another If in its if ’s body or in its else’s body.  The nested if can have one of the following 3 forms :- 1. If (expression 1) Then If (expression 2 ) Then Statement 1 Else Statement 2 End If Else body-of-else End If 2. If (expression 1) Then body-of-if Else : If (expression 2) Then Statement-1 Else Statement-2 End If
  • 8. 3. If (expression 1) Then : If (expression 2) Then Statement-1 Else Statement-2 End If Else If (expression 3) Then Statement-3 Else Statement-4 : End If End If Example of Nested If: If Num>0 Then Msgbox(“It is a positive number”) Else If Num<0 Then Msgbox(“It is a negative number”) Else Msgbox(“The number is equal to zero”) End If End If
  • 9. Select-Case Statement  Select-Case is a multiple branching statement and is used to executed a set of statements depending upon the value of the expression.  It is better to use Select-Case statement in comparison to If..Then..ElseIf Statement when the number of checks are more.  There are 3 different forms of using Select-Case statements and are given below :
  • 10. Different forms of Select-Case 1. Select Case : Simplest Form [Exact match] Select Case Expression Case Value ’visual basic statements Case Value ’visual basic statements Case Else ’visual basic statements End Select Example : Select Case byMonth Case 1,3,5,7,8,10,12 number_of_days=31 Case 2 number_of_days=28 Case Else number_of_days=30 End Select
  • 11. 2.Select Case : Second Form [Relational Test] Select Case Expression Case Is relation ’visual basic statements Case Is relation ’visual basic statements Case Else ’visual basic statements End Select Example: Select Case marks Case Is < 50 Result = “Fail” Case Is < 60 Result = “Grade B” Case Is < 75 Result = “Grade A” Case Else Result = “Grade A+” End Select
  • 12. 3.Select Case : Third Format [Range Check] Select Case Expression Case exp1 To exp2: ’visual basic statements Case exp1 To exp2: ’visual basic statements Case Else: ’visual basic statements End Select Example : Select Case Age Case 2 to 4 : Msgbox(“PreNursery”) Case 4 to 6 : Msgbox(“Kindergarden”) Case 6 to 10 : Msgbox(“Primary”) Case Else : Msgbox(“Others”) End Select