Posted by: wasaa | June 22, 2008

Control Structures



Control structures allow you to control the flow of your program’s execution.

If left unchecked by control-flow statements, a program’s logic will flow through statements from left to right, and top to bottom.




Selection (Branching)


Select Case



For Next

Do While

Do until

IF Statement

Branching statements are used to cause certain actions within a program if a certain condition is met.


If <condition > Then statement

If (Balance – Check) < 0 Then Print “You are overdrawn”

If Then and End If blocks

If Then and End If blocks allows multiple statements



IF <condition> then

statement 1

statement 2


statement n

end if

Select Case

Select Case testexpression
[Case expressionlist1
[Case expressionlist2
[Case Else
End Select

Visual Basic provides the Select Case structure as an alternative to If…Then…Else for selectively executing one block of statements from among multiple blocks of statements. A Select Case statement provides capability similar to the If…Then…Else statement, but it makes codes more readable when there are several choices.

The GoTo Statement

Another branching statement. The format is GoTo Label, where Label is a labeled line.

Labeled lines are formed by typing the Label followed by a colon.



Goto Line10


When you know you must execute statements a specific number of times,

For…Next loop is the better choice.

“For loop” uses a variable called a counter that increases or decreases in value during each repetition of the loop.




counter = start To end [Step increment]


[counter]The arguments counter, start, end, and increment are all numeric.

The increment argument can be either positive or negative.

If increment is positive, start must be less than or equal to end or the statements in the loop will not execute.

For i=1 to 100 step 5

If increment is negative, start must be greater than or equal to end for the body of the loop to execute.

For i=100 to 1 step -5

Do while

Do…Loop Use a Do loop to execute a block of statements an indefinite number of times. There are several variations of the Do…Loop statement. but each evaluates a numeric condition to determine whether to continue execution. Do…Loop, the statements execute as long as the condition is true:


Do While

statements Loop

When Visual Basic executes this Do loop,

it first tests condition.

If it’s True (nonzero), Visual Basic executes the statements and then goes back to the Do While statement and tests the condition again.

Another variation of the Do…Loop statement


Loop While conditionexecutes the statements first and then tests condition after each execution. This variation guarantees at least one execution of statements:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: