SlideShare a Scribd company logo
Conditional statements
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.

More Related Content

PPTX
Control Statements in Java
PPTX
Control statements in java
PPTX
Chapter 2 : Programming with Java Statements
PPTX
java programming- control statements
PDF
itft-Decision making and branching in java
PDF
Control structures in Java
PPT
Control statements in java programmng
PPT
Control structures i
Control Statements in Java
Control statements in java
Chapter 2 : Programming with Java Statements
java programming- control statements
itft-Decision making and branching in java
Control structures in Java
Control statements in java programmng
Control structures i

What's hot (20)

PPTX
C# conditional branching statement
PPTX
Control statement-Selective
PPTX
Control structures in java
PPTX
Control statements in Java
PPTX
Java Decision Control
PPTX
Control statements in java
PPTX
Selection statements
PPT
The Three Basic Selection Structures in C++ Programming Concepts
PPSX
Control Structures in Visual Basic
PPT
Control Structures
PPTX
If and select statement
PPTX
OCA JAVA - 2 Programming with Java Statements
PPT
Mesics lecture 6 control statement = if -else if__else
PPSX
Conditional statement
PPT
Control structures selection
PPTX
Switch statement, break statement, go to statement
PPT
Control structures ii
PPTX
Java if else condition - powerpoint persentation
PPT
Java control flow statements
C# conditional branching statement
Control statement-Selective
Control structures in java
Control statements in Java
Java Decision Control
Control statements in java
Selection statements
The Three Basic Selection Structures in C++ Programming Concepts
Control Structures in Visual Basic
Control Structures
If and select statement
OCA JAVA - 2 Programming with Java Statements
Mesics lecture 6 control statement = if -else if__else
Conditional statement
Control structures selection
Switch statement, break statement, go to statement
Control structures ii
Java if else condition - powerpoint persentation
Java control flow statements
Ad

Similar to Conditional statements (20)

PPTX
Using decision statements
PPTX
Decision statements
PPTX
BSc. III Unit iii VB.NET
PPTX
Unit IV Array in VB.Net.pptx
PDF
MA3696 Lecture 7
PPTX
Conditional statements
PPTX
Decision structures chpt_5
PPTX
Vb decision making statements
PPTX
Decision making
PPTX
If then statement
PPTX
Decisions
PPTX
Decisions
PPTX
Working with comparison operators
PPTX
If and select statement
PPT
Select Case
PPTX
Decisions
PPTX
Variable, constant, operators and control statement
PPTX
Variable, constant, operators and control statement
PDF
Conditional Statements & Loops
PPSX
البرمجة بلغة الفيجول بيسك
Using decision statements
Decision statements
BSc. III Unit iii VB.NET
Unit IV Array in VB.Net.pptx
MA3696 Lecture 7
Conditional statements
Decision structures chpt_5
Vb decision making statements
Decision making
If then statement
Decisions
Decisions
Working with comparison operators
If and select statement
Select Case
Decisions
Variable, constant, operators and control statement
Variable, constant, operators and control statement
Conditional Statements & Loops
البرمجة بلغة الفيجول بيسك
Ad

More from cherrybear2014 (12)

PPTX
Excel.t01
PPTX
Excel functions
PDF
Basics excel 20102
PPT
Session2
PPT
11 scripting languages
PPT
5 software design
PPT
Table tags 2
PPTX
Intro to html
PPTX
Designing the product page
PPTX
Check,combo,list,picture box
PPTX
Forms and buttons
Excel.t01
Excel functions
Basics excel 20102
Session2
11 scripting languages
5 software design
Table tags 2
Intro to html
Designing the product page
Check,combo,list,picture box
Forms and buttons

Conditional statements

  • 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.