SlideShare una empresa de Scribd logo
1 de 14
CONDITIONAL STATEMENT
Conditions are logical expressions that evaluate to a
True/False value and they usually contain comparison
operators— equals (=), different (<>), less than (<), greater
than (>), less than or equal to (<=), and so on — and logical
operators: And, Or, X or, and Not. Here are a few examples
of valid conditions:
 If (age1 < age2) And (age1 > 12) Then ...
If score1 = score2 Then ...
FORMS OF IF STATEMENT
1. if … statement then 1 condition
2. if … statement has Else part
3. if statement has one or more Else if parts
If … then statement
The If. . .Then statement tests an expression, which
is known as a condition. If the condition is True, the
program executes the statement(s) that follow.
The If. . .Then statement can have a single-line or a
multiple-line syntax. To execute one statement
conditionally, use the single-line syntax as follows:
If condition Then
statement is TRUE
End if
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If TextBox1.Text = "Hello!" Then Label1.Text =
"World"
End Sub
 Another example:
Dim a As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
a = TextBox1.Text
If a >= 18 Then label1.text ("You can now vote
online.")
End Sub
2. if … statement has Else part
If the condition is evaluates correct, then the
statement are executed.
If the condition is evaluates false, then the
statements are executed.
Syntax:
If condition Then
statement is True
Else
statement is False
End if
Dim a As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
a = TextBox1.Text
If a >= 18 Then Label1.Text = "You can now
vote online."
Else Label1.Text = "You can not vote“
End Sub
 Another Example:
(Using Boolean/Logical Operation)
If TextBox1.Text = “Apple" And / Or
TextBox2.Text = “Banana"
Then Label1.Text = "Fruit“
Else Label1.Text = “Junk Food"
3. if statement has one or more Elseif parts
One or more statements and condition.
Syntax:
If Condition1 then
statements to be if condition is true
Else if condition2 then
statements to be executed is False but Condition2 is True
Else if condition3 then
statements to be executed if Con1 and Con2 are False but
Condition3 is True
Else
statements to be executed if all of the above conditions are False.
End Sub
Dim Grade as Integer
Grade = txtgrade.Text
If Grade <= 74 Then MsgBox("You Failed!") Else If
Grade <= 80 Then MsgBox("Needs Improvement!") Else If
Grade <= 85 Then MsgBox("Average!") Else If Grade <= 90
Then MsgBox("Satisfactory!") Else If Grade <= 95 Then
MsgBox("Very Satisfactory!") Else MsgBox("Excellent!")
End Sub
Note:
 Aside from Message box, you may also use the
controls such as label and textbox, if you want to
show the executed statements or condition.

Más contenido relacionado

La actualidad más candente

Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in JavaJin Castor
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual BasicTushar Jain
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
If and select statement
If and select statementIf and select statement
If and select statementRahul Sharma
 
OCA JAVA - 2 Programming with Java Statements
 OCA JAVA - 2 Programming with Java Statements OCA JAVA - 2 Programming with Java Statements
OCA JAVA - 2 Programming with Java StatementsFernando Gil
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selectionOnline
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentationManeesha Caldera
 

La actualidad más candente (20)

C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Selection statements
Selection statementsSelection statements
Selection statements
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
Control Structures
Control StructuresControl Structures
Control Structures
 
If and select statement
If and select statementIf and select statement
If and select statement
 
OCA JAVA - 2 Programming with Java Statements
 OCA JAVA - 2 Programming with Java Statements OCA JAVA - 2 Programming with Java Statements
OCA JAVA - 2 Programming with Java Statements
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentation
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 

Similar a Conditional Logic and Statements in 40 Characters

BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
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
 
Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a programYsa Castillo
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c languagechintupro9
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
03a control structures
03a   control structures03a   control structures
03a control structuresManzoor ALam
 
If and select statement
If and select statementIf and select statement
If and select statementRahul Sharma
 
Intruduction conditional statement
Intruduction conditional statementIntruduction conditional statement
Intruduction conditional statementKhwaja Agha Karimi
 
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
 
Week 3 Lecture 11 Regression Analysis Regression analy.docx
Week 3 Lecture 11 Regression Analysis Regression analy.docxWeek 3 Lecture 11 Regression Analysis Regression analy.docx
Week 3 Lecture 11 Regression Analysis Regression analy.docxcockekeshia
 
What are conditional statements?
What are conditional statements?What are conditional statements?
What are conditional statements?AnuragSrivastava272
 
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
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptxGerlieLorente
 
Working with comparison operators
Working with comparison operatorsWorking with comparison operators
Working with comparison operatorsSara Corpuz
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)TejaswiB4
 

Similar a Conditional Logic and Statements in 40 Characters (20)

Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
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
 
Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a program
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
03a control structures
03a   control structures03a   control structures
03a control structures
 
If and select statement
If and select statementIf and select statement
If and select statement
 
LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
 
Intruduction conditional statement
Intruduction conditional statementIntruduction conditional statement
Intruduction conditional statement
 
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
 
How to Program
How to ProgramHow to Program
How to Program
 
Week 3 Lecture 11 Regression Analysis Regression analy.docx
Week 3 Lecture 11 Regression Analysis Regression analy.docxWeek 3 Lecture 11 Regression Analysis Regression analy.docx
Week 3 Lecture 11 Regression Analysis Regression analy.docx
 
What are conditional statements?
What are conditional statements?What are conditional statements?
What are conditional statements?
 
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
 
Conditional Statements.pptx
Conditional Statements.pptxConditional Statements.pptx
Conditional Statements.pptx
 
Working with comparison operators
Working with comparison operatorsWorking with comparison operators
Working with comparison operators
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 

Más de cherrybear2014 (12)

Excel.t01
Excel.t01Excel.t01
Excel.t01
 
Excel functions
Excel functionsExcel functions
Excel functions
 
Basics excel 20102
Basics excel 20102Basics excel 20102
Basics excel 20102
 
Uml
UmlUml
Uml
 
Session2
Session2Session2
Session2
 
11 scripting languages
11 scripting languages11 scripting languages
11 scripting languages
 
5 software design
5 software design5 software design
5 software design
 
Table tags 2
Table tags 2Table tags 2
Table tags 2
 
Intro to html
Intro to htmlIntro to html
Intro to html
 
Designing the product page
Designing the product pageDesigning the product page
Designing the product page
 
Check,combo,list,picture box
Check,combo,list,picture boxCheck,combo,list,picture box
Check,combo,list,picture box
 
Forms and buttons
Forms and buttonsForms and buttons
Forms and buttons
 

Conditional Logic and Statements in 40 Characters

  • 1.
  • 3. Conditions are logical expressions that evaluate to a True/False value and they usually contain comparison operators— equals (=), different (<>), less than (<), greater than (>), less than or equal to (<=), and so on — and logical operators: And, Or, X or, and Not. Here are a few examples of valid conditions:
  • 4.  If (age1 < age2) And (age1 > 12) Then ... If score1 = score2 Then ...
  • 5. FORMS OF IF STATEMENT 1. if … statement then 1 condition 2. if … statement has Else part 3. if statement has one or more Else if parts
  • 6. If … then statement The If. . .Then statement tests an expression, which is known as a condition. If the condition is True, the program executes the statement(s) that follow. The If. . .Then statement can have a single-line or a multiple-line syntax. To execute one statement conditionally, use the single-line syntax as follows: If condition Then statement is TRUE End if
  • 7. Code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "Hello!" Then Label1.Text = "World" End Sub
  • 8.  Another example: Dim a As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click a = TextBox1.Text If a >= 18 Then label1.text ("You can now vote online.") End Sub
  • 9. 2. if … statement has Else part If the condition is evaluates correct, then the statement are executed. If the condition is evaluates false, then the statements are executed. Syntax: If condition Then statement is True Else statement is False End if
  • 10. Dim a As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click a = TextBox1.Text If a >= 18 Then Label1.Text = "You can now vote online." Else Label1.Text = "You can not vote“ End Sub
  • 11.  Another Example: (Using Boolean/Logical Operation) If TextBox1.Text = “Apple" And / Or TextBox2.Text = “Banana" Then Label1.Text = "Fruit“ Else Label1.Text = “Junk Food"
  • 12. 3. if statement has one or more Elseif parts One or more statements and condition. Syntax: If Condition1 then statements to be if condition is true Else if condition2 then statements to be executed is False but Condition2 is True Else if condition3 then statements to be executed if Con1 and Con2 are False but Condition3 is True Else statements to be executed if all of the above conditions are False. End Sub
  • 13. Dim Grade as Integer Grade = txtgrade.Text If Grade <= 74 Then MsgBox("You Failed!") Else If Grade <= 80 Then MsgBox("Needs Improvement!") Else If Grade <= 85 Then MsgBox("Average!") Else If Grade <= 90 Then MsgBox("Satisfactory!") Else If Grade <= 95 Then MsgBox("Very Satisfactory!") Else MsgBox("Excellent!") End Sub
  • 14. Note:  Aside from Message box, you may also use the controls such as label and textbox, if you want to show the executed statements or condition.