Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

Working with vb.

net
control statement
Group 2 presents 9- gemini
VB.NET Control Statements
In VB.NET, the control statements are the statements that
controls the execution of the program on the basis of the specified
condition. 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, Select Case, Nested Select Case,
Flowchart of Control statements.
We can define more than one condition to be evaluated by the
program with statements. If the defined condition is true, the
statement or block executes according to the condition, and if the
condition is false, another statement is executed.
VB.NET provides the following conditional or
decision-making statements.

• If-Then Statement • Select Case Statement

• If-Then Else Statement • Nested Select Case Statements

• If-Then ElseIf • Flowcharts of Control Statements


Statement
If-Then Statement
An If...Then statement consists of a boolean expression
followed by one or more statements. It is the simplest form of
control statement, frequently used in decision making and
changing the control flow of the program execution.

If-Then Statement can execute single or multiple statements


when the condition is true, but when the expression evaluates
to false, it does nothing. So, here comes the If-Then-
Else Statement. The IF-Then-Else Statement is telling
what If condition to do when if the statement is false, it executes
the Else statement.
If-Then Statement (Syntax)

If (condition) Then
[Statement(s)]
End If
(Syntax)
If-Then Statement If (condition) Then
[Statement(s)]
End If
Example:
Dim age As Integer
age = 20
If age >= 18 Then
Console.WriteLine("You are eligible to vote.")
End If
If-Then Else Statement
The If-Then Statement can execute single or multiple
statements when the condition is true, but when the expression
evaluates to false, it does nothing. So, here comes the If-Then-
Else Statement. The IF-Then-Else Statement is telling
what If condition to do when if the statement is false, it
executes the Else statement.
If-Then Else Statement
Syntax:
If (Boolean_expression) Then
‘ This statement will execute if the Boolean condition is true
Else
'Optional statement will execute if the Boolean condition is false
End If
If-Then Else Statement
Example:
Dim num As Integer = 7

If num Mod 2 = 0 Then


Console.WriteLine("The number is
even.")
Else
Console.WriteLine("The number is
odd.")
End If
If-Then ElseIf Statement
The If-Then-ElseIf Statement provides a choice
to execute only one condition or statement from
multiple statements. Execution starts from the top to
bottom, and it checked for each If condition. And if the
condition is met, the block of If the statement is
executed. And if none of the conditions are true, the
last block is executed.
If-Then ElseIf Statement
Syntax:
If(condition 1)Then
' Executes when condition 1 is true
ElseIf( condition 2)Then
' Executes when condition 2 is true
ElseIf( boolean_expression 3)Then
' Executes when the condition 3 is true
Else
' executes the default statement when none of the above conditions i
s true.
End If
If-Then ElseIf Statement
Dim score As Integer
Example: Score = 75
If score >= 90 Then
Console.WriteLine("Excellent! You got an A.")
ElseIf score >= 80 Then
Console.WriteLine("Well done! You got a B.")
ElseIf score >= 70 Then
Console.WriteLine("Good job! You got a C.")
Else
Console.WriteLine("You need to improve your
score.")
End If
Select Case Statement
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.

The Select Case statement is a collection of multiple case


statements, which allows executing a single case statement from
the list of statements. A selected case statement uses a variable to
test for equality against multiple cases or statements in a
program. If the variable is matched with any test cases, that
statement will be executed. And if the condition is not matched
with any cases, it executes the default statement.
Select Case Statement
Syntax:
Select Case expression
Case value1
' Statements to execute if expression matches value1
Case value2
' Statements to execute if expression matches value2
' Continue Case blocks as needed
Case Else
' Statements to execute if expression doesn't match any
values
End Select
Example:
Dim dayOfWeek As Integer = 3
Dim dayName As String = ""
Select Case Statement
Select Case dayOfWeek
Case 1
dayName = "Sunday"
Case 2
dayName = "Monday"
Case 3
dayName = "Tuesday"
Case 4
dayName = "Wednesday"
Case 5
dayName = "Thursday"
Case 6
dayName = "Friday"
Case 7
dayName = "Saturday"
End Select
Console.WriteLine("Today is " & dayName & ".")
Nested Select Case Statement
A nested Select Case statement refers to a scenario where
one or more Select Case statements are placed within another
Select Case statement. This structure allows for more granular
control over decision-making in the code by evaluating multiple
expressions and executing corresponding blocks of code based
on the values of those expressions.
Nested Select Case Statement
Syntax:Select Case expression1
Case value11
' Statements to execute if expression1 matches value11
Select Case expression2
Case value21
' Statements to execute if expression2 matches value21
Case value22
' Statements to execute if expression2 matches value22
' Continue Case blocks as needed
Case Else
' Statements to execute if expression2 doesn't match any values
End Select
Case value12
' Statements to execute if expression1 matches value12
' Continue Case blocks for expression1 as needed
Case Else
' Statements to execute if expression1 doesn't match any values
End Select
Dim grade As Integer = 75
Dim comment As String = ""
Nested Select Case Statement
Select Case grade
Case 90 To 100
Example: comment = "Excellent!"
Case 80 To 89
comment = "Good job!"
Case 70 To 79
comment = "Fair."
Case 60 To 69
comment = "Needs improvement."
Case Else
comment = "Fail."
End Select

Select Case comment


Case "Excellent!", "Good job!"
Console.WriteLine("You did well.")
Case "Fair."
Console.WriteLine("You did okay.")
Case "Needs improvement.", "Fail."
Console.WriteLine("You need to study harder.")
End Select
Flowchart Control Statement
A flowchart control statement refers to the visual
representation of the flow of control or logic within a program
using standard flowchart symbols. Flowcharts are graphical
diagrams that illustrate the sequence of steps, decisions, and
actions in an algorithm or program.

While flowchart control statements themselves are not


directly implemented in VB.NET code, they are used as a visual
aid to design, plan, and understand the flow of control structures
within VB.NET programs.
Key Elements of Flowchart Control Statement

Start/End Symbols:
These symbols represent the beginning and end points of
the flowchart. In a VB.NET program, this corresponds to the
start and end of the main program or a specific subroutine or
function.
Process Symbols:
These symbols represent actions or operations
performed within the program, such as calculations,
assignments, or function calls.
Key Elements of Flowchart Control Statement
Decision Symbols:
These symbols represent points in the flowchart where
decisions are made based on conditions. In VB.NET, this
corresponds to If-Then-Else or Select Case statements.

Input/Output Symbols:
These symbols represent input and output
operations, such as reading data from the user or
displaying information to the user.
Key Elements of Flowchart Control Statement

Connector Symbols:
These symbols are used to connect
different parts of the flowchart and indicate the
flow of control from one step to another.
THANK
YOUGroup 2 presents 9-Gemini
Group Members And their
Questioner:
Leader: Role Stephanie Casiles
JohnCris A Sebastian
Roseleen Bisconde
Reporter:
Chloe Kyle Eneja
John Cris Sebastian
Rhian Rose Aguirre
Christine Jade Bueno
PPT Creator & Loptop Provider:
Dawn Eli Mar Ruiz
Czarina Michelle
John Patrick Altares
Norberte
Performance Task:
Zaira Mariano
John Karl Bayatan
John Cris Sebastian
Gian Andrei Tomas
Researcher:
Dave Ducusin
John Patrick Altares

You might also like