goto
statement—it is not necessary
for making the language complete. Rather,
goto
is a convenience that, if used wisely, can be
a benefit in certain programming situations. As such, the
goto
is not used in this book
outside of this section. The chief concern most programmers have about the
goto
is its
tendency to clutter a program and render it nearly unreadable. However, there are times
when the use of the
goto
can clarify program flow rather than confuse it.
The
goto
requires a label for operation. A
label
is a valid C# identifier followed by a
colon. The label must be in the same method as the
goto
that uses it and within scope. For
example, a loop from 1 to 100 could be written using a
goto
and a label, as shown here:
x = 1;
loop1:
x++;
if(x < 100) goto loop1;
www.freepdf-books.com
106
P a r t I :
T h e C # L a n g u a g e
The
Do'stlaringiz bilan baham: |