1. Control Structures
In Visual Basic
Submitted By:
Sakar Chiolunkar
Shashank Baghel
Tushar jain
12C3045
12C3053
LOGO
12C3062
2. Control Statement
The order in which statements are executed in a program is
called the flow of control. In a sense, the computer is under the
control of one statement at a time. When a statement has been
executed, control is turned over to the next statement (like a
baton being passed in a relay race). Flow of control is normally
sequential. That is, when one statement is finished executing,
control passes to the next statement in the pro- gram. If we
want the flow of control to be nonsequential, you can use
control structure.
Company Logo
3. Control Flow
In a program, statements may be executed sequentially, selectively or iteratively.
Every programming language provides constructs to support sequence, selection
or iteration. So there are three types of programming constructs :
Sequence
Functions and Procedures
Selection
If...Then...Else statement
Select Case statement
Iterative
Company Logo
For...Next Loop statement
Do...Loop statement
4. Sequential Construct
The sequential construct means the statements are being
executed sequentially. This represents the default flow of
statements.
Statement 1
Statement 2
Statement 3
5. Selection Construct
The selection construct means the execution of statement(s) depending upon the
condition-test. If a condition evaluates to true, a course-of-action (a set of statements)
is followed otherwise another course-of-action is followed. This construct is also
called decision construct as it helps in decision making.
Condition
?
true
Statement 1
false
One course-of-action
Statement 1
Another course
of action
Statement 2
Statement 2
6. If...Then...Else statement
Perhaps the most important statement in a program is the If statement and then its
statements. In other words
If.. Then.. Else statement provides an alternate choice to the user i.e. if the
condition is true then a set of statements are executed otherwise another set of
statements are executed.
In Visual Basic we use three types of ‘IF’ statements:
1. Simple If
2. If Else
3. Nested If
8. Select Case statement
If we have a lot of conditional statements, using If..Then..Else could be very
messy. For multiple conditional statements, it is better to use Select Case or
Select Case allows multi way branching through the code.
Syntax :
Select Case expression ‘expression maybe string or numeric
Case value1
Block of one or more VB statements
Case value2
Block of one or more VB Statements
Case value3
Block of one or more VB statements
Case value4
.
.
.
Case Else
Block of one or more VB Statements
End Select
9. Select Case statement
Case 1
true
Case 1 Statements
false
Case 2
true
Case 2 Statements
false
Case N
true
Case Else Statements
Case N Statements
10. Iterative Constructs
The iterative or repetitive constructs means repetition of a set-of-statements
depending upon a condition-test. A set-of-statements are repeated again and
again till the condition or Boolean Expression evaluates to true. The iteration
constructs are also called as looping constructs.
false
The exit condition
Condition
?
True
Statement 1
The loop
body
Statement 2
11. For...Next Loop statement
Repeats a group of statements a specified number of times.
Syntax :
For counter [ As datatype ] = start To end [ Step step ]
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ counter ]
12. Do...Loop statement
Repeats a block of statements while a Boolean condition is True or
until the condition becomes True.
Syntax :
Do { While | Until } condition
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop
-orDo
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop { While | Until } condition