0% found this document useful (0 votes)
5 views

Variables Constant Operators and Control Statement

Uploaded by

kentakenaka26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Variables Constant Operators and Control Statement

Uploaded by

kentakenaka26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Variable, Constant, Operators

and Control Statement


Variables
• Programming element used to store a
value in the program while the program
is running.
• It is a name area in the memory which
holds temporary data.
EXAMPLE:
Name = “Shaira”
Age = text1.text
• EXPLICIT DECLARATION – declaring variable by
typing DIM (dimension) statement and a
variable name.
Syntax: Dim Variable Name As Data type
Example:
Dim LastName As String
• IMPLICIT DECLARATION – declaring a variable
without the Dim Statement; simply use the
variable on its own.
Example:
LastName=“Fernandez”
Constant
• Meaningful Name that takes place of a
number or a string that does not change.
• Values that do not change during the
execution of the program.
Syntax: Const Constant Name As data type =
value
Example:
const Pi As Single = 3.142
Score= 100
Operators
• Operators are symbols that indicates
operation to be performed on data.
There are 3 types of Operators
1. Arithmetic Operators
2. Relational Operators
3. Conditional Operators
Arithmetic Operators- Mathematical
Operators that is used to compute
inputs from users to generate results.
Relational Operators – Operators that is
used to compare two values basing on
a certain conditions yields a TRUE or
FALSE result.
Logical Operators – Operators that
determine if a particular condition is
met.
NEXT
Operators Description Example Result
+ Add 5+5 10
- Substract 10-5 5
/ Divide 25/5 5

\ Integer Division 20\3 6


(disregards the decimal places)

* Multiply 5*4 20

^ Exponent (power of) 3^3 27

Mod Remainder of division 20 Mod 6 2

"George"&"
& String concatenation "George Bush"
"&"Bush"
Operators Description Example Result

> Greater than 10>8 True

< Less than 10<8 False


Greater than
>= 20>=10 True
or equal to
Less than or
<= 10<=20 True
equal to
<> Not Equal to 5<>4 True
= Equal to 5=7 False
Operators Description

Operation will be true if either of the


OR
operands is true
Operation will be true only if both the
AND
operands are true
One sides or other must be true but
XOR
not both sides

NOT Negate truth


Condition of AND Operator
CONDITION 1 CONDITION2 RESULT
TRUE TRUE
TRUE FALSE
FALSE TRUE
FALSE FALSE
•If there’s a FALSE the result is false.
Condition of OR Operators
CONDITION 1 CONDITION2 RESULT
TRUE TRUE
TRUE FALSE
FALSE TRUE
FALSE FALSE
•If there’s a TRUE the result is true.
Condition of XOR Operator
CONDITION 1 CONDITION2 RESULT
TRUE TRUE
TRUE FALSE
FALSE TRUE
FALSE FALSE
•One sides or other must be true but not both
sides
Condition of NOT Operator

CONDITION RESULT
TRUE
FALSE

• Negate truth
Get a ¼ sheet of Paper
Find the result

1. 9+7+8 6. 10>1
2. 8^3 7. .05>.5
3. 65/13 8. 1500>=150100
4. 95 mod 955 9.0>=0.00
5. (-5)+(-4) 10.5<>10
Find the result

1. 10*10<100 And 12<>12


2. 500=500.0 Or 95-15<85
3.True And False
4.Not False
5.1000/100>77 And 96<>95
ANSWER KEY

• 1. 24 •6. TRUE • 1. FALSE


• 2. 512 •7. FALSE • 2. TRUE
• 3. 5 •8. FALSE • 3. FALSE
• 4. 5 •9. TRUE • 4. TRUE
•10. TRUE • 5. FALSE
• 5. -9
CONDITIONAL STATEMENT
Conditional Statement
• It is one of the vital components
in programming. It enables a
program to respond in different
manner every time a program is
executed depending on the data
entered.
Most Commonly Used Conditional
Statement.
1. If.. Then Statement
2. If.. Then.. Else Statement
3. If.. Then.. ElseIf Statement
4. Select Case Statement
If.. Then Statement
• The If...Then statement examines the
truthfulness of an expression. It allows
your Program to make a decision based
on the certain condition.
• SYNTAX:
If condition then
Statement/s
End If
If.. Then.. Else Statement
• The If...Then statement offers only
one alternative: to act if the
condition is true. Whenever you
would like to apply an alternate
expression in case the condition is
false, you can use the
If...Then...Else statement.
If.. Then.. Else Statement
SYNTAX:
If Condition Then If Score = 100 Then
Statement1 Label1.caption =“Perfect”
Else
Else Label1.caption =“with
Mistakes”
Statement2
End If
End If
If...Then...ElseIf Statement
SYNTAX:
The If...Then...ElseIf
If Condition1 Then
statement acts like
Statement1
the If...Then...Else
ElseIf Condition2 Then
expression, except
Statement2
that it offers as
ElseIf Condition 3 Then
many choices as
Statement 3
necessary.
End If
SELECT CASE STATEMENT
• If you have a large number of
conditions to examine,
the If...Then...Else will go through
each one of them. Visual Basic offers
the alternative of jumping to the
statement that applies to the state of
the condition.
Syntax
Select Case Expression
Case Expression1 Select Case Subject

Statement1 Case “Mathematics”


Case Expression2 lblsubject.caption=“Mathematics”
Statement2
Case “Science”
Case Expression3 lblsubject.caption=“Science”
Statement3
Case “English”
End Select lblsubject.caption=“English”

End Select
LOOP Structure

• A loop is an expression used to


repeat an action. Visual Basic
presents many variations of the
loops and they combine
the Do and the Loop keywords.
Do...While Loop
• Used to execute a block of statements in
an unspecified number of times while a
condition is false on the first pass. The
statement is not executed.
Syntax: Dim Number As Integer
Number = 10
Do while conditions
Do While Number <20
Statement/s Number=Number+2
loop Print Number
Loop
Do...Loop...While Statement
Reverse formula of
the do while Dim Number As Integer
statement. Number = 10
Syntax: Do
Do Number=Number+2
Statement(s) Print Number
Loop While Loop While Number <20
Condition
Do...Until...Loop Statement
• This loop will first examine the Condition,
instead of examining whether the Condition is
true, it will test whether the Condition is false.
Syntax: Example:
Do Until Condition Dim Number As Integer
Statement(s) Number=30
Loop Do Until Number <=20
Number= Number-2
Print Number
Loop
Do...Loop...Until Statement
• An alternative to the Do...Until...loop consists
of executing the Statement first.
Example:
Syntax: Dim Number As Integer
Do Number=30
Statement(s) Do
Loop Until Number= Number-2
Condition Print Number
Loop Until Number <=20

You might also like