Professional Documents
Culture Documents
and If-Then
Selection Structure
ENSC 26 Laboratory
VARIABLES AND DATA TYPES
Data Type
A property of a variable which defines the values that the variable can take, the
programming language used, or the operations that can be performed on it.
The following data types are used in Visual BASIC:
1. Arithmetic Operators
2. Shortcut Operators
3. Comparison Operators
4. Logical Operators
5. Concatenation Operator
OPERATORS
Arithmetic Operators
The priority of operation is as follows: ^, *, /, \, mod, +, -.
Example: 8 \10 / 5 mod 3 = 1
OPERATORS
Operators
The assignment operator (=) can be preceded by an arithmetic operator (except
Mod) to create shortcut expressions
Example: If Value = 8
OPERATORS
Comparison Operators
Note that all comparison operators have equal precedence.
Other comparison operators include Is, IsNot, and Likewhich shall be discussed on later
chapters.
OPERATORS
Logical Operators
Logical operators have the following order of precedence: negation (Not), conjunction (And,
AndAlso), inclusive disjunction (Or, OrElse), and exclusive disjunction (Xor).
EXPRESSING PROGRAM ALGORITHMS
Flowcharts
Flowchart is a graphical
representation of an
algorithm to define its
logical flow.
It illustrates the steps of an
algorithm by using different
kinds of boxes which are
ordered by connecting
them with arrows (shown
on the right).
EXPRESSING PROGRAM ALGORITHMS
Flowcharts
The algorithm for a Celsius-
To-Kelvin program can be
expressed as:
DECISION/SELECTION STRUCTURES
If-Then Statements
A conditional statement used in directing program flow based on multiple decision
criteria.
It has an equivalent to the English form:
“If such-and-such is true, then do so-and-so.”
General forms:
A. Single Selection
1. Single line If statement
2. If…Then
B. Multiple Selection
3. If…Then…Else
4. Nested If…Then.. Else
5. If…Then…ElseIf
DECISION/SELECTION STRUCTURES
If-Then Statements
Single-Line Syntax:
If…Then… Syntax:
Else
If...Then...Else Syntax:
If
Then
DECISION/SELECTION STRUCTURES
If-Then Statements
Nested If...Then...Else Syntax
Nesting is the process of embedding program statements in other statements
Below is the syntax for Nested If-Then Statements:
DECISION/SELECTION STRUCTURES
Assigning Condition in If-Then Statements
Below are condition statements that include conditional operators and results to a
Boolean value (True or False):
If several conditions are to be used, logical operators are used to combine conditions
into one larger condition:
SAMPLE PROBLEM
SAMPLE PROBLEM
SAMPLE PROBLEM
SAMPLE PROBLEM
SAMPLE PROBLEM