View contents of this chapter

While....Wend Loop

Visual Basic also provides another general purpose loop statement called the While...Wend loop. The Wend keyword is short for while end.

While condition
  [statements]
Wend

An Early Exit

Sometimes, depending on the data, you may want to terminate an event or other kind of procedure early. You can combine the If and Exit statement to do that.

The Exit Statement has the following format:

Exit Sub | Function | Do | For

The vertical bars between keywords indicate that only one of these keywords can follow Exit.

Consider the following code segment:

Private Sub calc()
 If (value < 100) then
   Exit Sub   'Terminates the procedure
 Else
   lblvalue.Caption = 100
 End If
End Sub

Play Sound To Exit from a Function , use Exit Function.

Play Sound

In this chapter, you have seen how to control your programs. By adding conditional operators to your program, you can make VB analyze data and respond according to the values inside variables. Moreover, in this chapter, we also discussed about the looping statements, which can be used to repeat a section of code more than once.



© Universal Teacher Publications        INDEX Previous Screen Next Screen