You may also come across instances in which you need to exit a loop prematurely.
In these cases, you would use either Exit, if your code is in VB, or the equivalent
(break) statement in C#, to terminate the loop:
Visual Basic
Dim i As Integer
For i = 0 To 10
If (i = 5) Then
Response.Write("Oh no! Not the number 5!!")
Exit For
End If
Next
C#
int i;
for (i = 0; i <= 10; i++)
{
if (i == 5)
{
Response.Write("Oh no! Not the number 5!!");
break;
}
}
In this case, as soon as our For loop hits the condition i = 5, it displays a
warning message using the Response.Write method (which will be familiar to
those with past ASP experience), and exits the loop so that no further passes
through the loop will be made.
Although weve only scratched the surface, VB and C# provide a great deal of
power and flexibility to web developers, and time spent learning the basics now
will more than pay off in the future.
Object Oriented Programming Concepts
VB and C# are modern programming languages that give you the tools to write
structured, extensible, and maintainable code. The code can be separated into
modules, each of which defines classes that can be imported and used in other
modules. Both languages are relatively simple to get started with, yet they offer
sophisticated features for writing complex, large-scale enterprise applications.
One of the reasons why these languages are so powerful is that they facilitate
object oriented programming (OOP). In this section, well explain the funda-
76
Chapter 3: VB and C# Programming Basics

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.