Professional Documents
Culture Documents
Chpter 5
Chpter 5
NET
PROGRAMMING
Program-Control
Statements
Chapter 5:
Objective
Program-Control Statements
Like any programming language, the control statements are the essence
of VB programming language because it governs the flow of program
execution. The way they are implemented in many ways defines the
personality of the VB language.
Chapter 5:
Program-Control Statements
Example:
Chapter 5:
Example:
Chapter 5:
While loop
While loop
Example:
Chapter 5:
While loop
Example:
Chapter 5:
Do While loop
The do-while loo[, like the repeat-until syntax of other languages, does
not check the condition until after the loop code block is executed, so the
code block will always be run at least once with do-while.
Chapter 5:
Do While loop
General syntax: The condition can be any valid VB
Do { While | Until } condition expression that evaluates to a Boolean
[statements] value.
[Exit Do]
[statements]
The code block can be any valid VB
Loop code.
or
Do
[statements]
[Exit Do]
[statements]
Loop { While | Until } condition
Chapter 5:
Do While loop
Example
Chapter 5:
Do While loop
Example
Chapter 5:
Do While loop
Example
Chapter 5:
For Loop
For loop indicates the starting value for the loop control variable, the test
condition that controls loop entry, and the expression that alters the loop
control variable all in one convenient place.
Chapter 5:
For Loop
General syntax:
For counter [ As datatype] = star To end [Step step]
[statements
[exit for]
[statements]
Next [counter]
For loop begins with the reserved word “for” followed by a st of parentheses, and the three sections
are:
Initializing the loop control variable
Testing the loop control variable
Updating the loop control variable
Chapter 5:
For Loop
Example
Chapter 5:
For Loop
Example