5 Control Structures

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

Computer

Programming
2

Control Structures
Control Structures
• Allows the programmer to alter the normal flow of
statement execution.

Types of Control structures:


1. Loop
2. Decision
Control Structures
Types of Decision Structures:
• The Block If Statement
Simple alternative - if
Compound alternative - if….else
• Select Case Statement
If Statement
An action is taken if the condition is true, otherwise
the control goes to the next statement.

Syntax:
If condition Then
action(s)
End if
Using If Statement
• Use indentation.
• In the nested If statement, each If must have its own
End If statement.
• Care should be taken to make If blocks easy to
understand.
Relational Operators
MATHEMATICAL VISUAL BASIC NUMERIC MEANING
NOTATION NOTATION
= = Equal to
# <> Unequal to
< < Less than
> > Greater than
<= <= Less than or equal
>= >= Greater than or equal
Logical Operators
• The result of a logical operator is also True or False.

OPERATOR SYMBOL
AND And
OR Or
NOT <>
Assignment Statements
• The simplest statement is the assignment statement.
It consists of a variable name (var), followed by the
assignment operator (=), followed by an expression
(expr).
Example:
StartTime = Now
Explorer.Caption = “Captain marvel”
count = count + 1
num = 5
count = count + num /2
Comment Statements
• An apostrophe (‘) can be used to indicate comments;
comments are ignored by Visual Basic.

• The keyword Rem can also be used instead of an


apostrophe for comments.

• Remarks can also be placed after program statement


too.

You might also like