Board index » delphi » GOTO Statement in TP

GOTO Statement in TP

Hi all.

I have been learning turbo Pascal now for the past 2 years.  Lately I have
been reading some new books on the topic and last night I ran across the
topic of GOTO statements in TP.  Now, the book explicitly said "You should
never use a GOTO statement in a Pascal program."  Ok that's fine, we should
never use them, but why does the language have the option then?  What about
if we said "You should never use a FOR statement in a Pascal program?"

Kevin

 

Re:GOTO Statement in TP


In article <QmYj4.212596$5r2.572...@tor-nn1.netcom.ca>,
  "Kevin Long" <kl...@netcom.ca> wrote:

Quote
> Hi all.

> I have been learning turbo Pascal now for the past 2 years.  Lately
> I have been reading some new books on the topic and last night I ran
> across the topic of GOTO statements in TP.  Now, the book explicitly
> said "You should never use a GOTO statement in a Pascal program."  Ok
> that's fine, we should never use them, but why does the language have
> the option then?  What about if we said "You should never use a FOR
> statement in a Pascal program?"

Then we would use the while and repeat...until constructions, which have
the added advantage that they do no rely on the implementation dependent
behaviour of a loop variable.

BTW, the book is wrong. Using GOTO is not considered good programming
style, but when used judiciously it can occasionally be useful.

Robert
--
Robert AH Prins
prin...@willis.com

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:GOTO Statement in TP


Quote
"Kevin Long" <kl...@netcom.ca> wrote:
>I have been learning turbo Pascal now for the past 2 years.  Lately I have
>been reading some new books on the topic and last night I ran across the
>topic of GOTO statements in TP.  Now, the book explicitly said "You should
>never use a GOTO statement in a Pascal program."  Ok that's fine, we should
>never use them, but why does the language have the option then?  What about
>if we said "You should never use a FOR statement in a Pascal program?"

The FOR statement is structured, GOTO is unstructured.

Jud McCranie

Re:GOTO Statement in TP


In article <QmYj4.212596$5r2.572...@tor-nn1.netcom.ca>,

Quote
Kevin Long <kl...@netcom.ca> wrote:
>Hi all.

>I have been learning turbo Pascal now for the past 2 years.  Lately I have
>been reading some new books on the topic and last night I ran across the
>topic of GOTO statements in TP.  Now, the book explicitly said "You should
>never use a GOTO statement in a Pascal program."  Ok that's fine, we should
>never use them, but why does the language have the option then?  What about
>if we said "You should never use a FOR statement in a Pascal program?"

You should never say never. While Goto should not be used as the basic
method of slow control, it has uses in error situations. Sure you can
write all those without goto also but that can make things more
complicated.

TP 7.0 added Break and continue that can be used to avoid Gotos.
However, i sometimes wonder are they that good. Goto has a clearly
market target and it does not change no matter what you do to the code
near the Goto., With Break on the other hand the behavior changes
completely if you put the break inside an inner loop.

You should use GOTO only after you have first learned to program without
it.

Osmo

Re:GOTO Statement in TP


Quote
Kevin Long <kl...@netcom.ca> wrote:
> Hi all.
> I have been learning turbo Pascal now for the past 2 years.  Lately I have
> been reading some new books on the topic and last night I ran across the
> topic of GOTO statements in TP.  Now, the book explicitly said "You should
> never use a GOTO statement in a Pascal program."  Ok that's fine, we should
> never use them, but why does the language have the option then?  What about
> if we said "You should never use a FOR statement in a Pascal program?"
> Kevin

Hi,

the GOTO statement is a relict out of the times when BASIC was state of art.
In the current programming techniques GOTO statements are banned because
they are a terrible kind of programming. But sometimes or better some people
think that they must use GOTO. Or sometimes even PASCAL itself uses GOTO in
while loops. So they implemented this statement even they know that GOTO is
deprecated.

Cu
Toralf

Re:GOTO Statement in TP


Re:GOTO Statement in TP


Quote
Kevin Long <kl...@netcom.ca> wrote in message

news:QmYj4.212596$5r2.572929@tor-nn1.netcom.ca...
Quote
> Hi all.

> I have been learning turbo Pascal now for the past 2 years.  Lately I have
> been reading some new books on the topic and last night I ran across the
> topic of GOTO statements in TP.  Now, the book explicitly said "You should
> never use a GOTO statement in a Pascal program."  Ok that's fine, we
should
> never use them, but why does the language have the option then?  What
about
> if we said "You should never use a FOR statement in a Pascal program?"

> Kevin

YOU can use it,but all the books write it because GOTO statement is
 cotrary to  procedural programming.
 I had theachers that didn't accept  the homeworks with GOTO statements.
 FOR, REPEAT UNTIL , WHILE DO is produced instead of GOTO ,and they are
really more useful.

T1000

Re:GOTO Statement in TP


Quote
Kevin Long <kl...@netcom.ca> wrote in message

news:QmYj4.212596$5r2.572929@tor-nn1.netcom.ca...
Quote
> Hi all.

> I have been learning turbo Pascal now for the past 2 years.  Lately I have
> been reading some new books on the topic and last night I ran across the
> topic of GOTO statements in TP.  Now, the book explicitly said "You should
> never use a GOTO statement in a Pascal program."  Ok that's fine, we
should
> never use them, but why does the language have the option then?  What
about
> if we said "You should never use a FOR statement in a Pascal program?"

> Kevin

YOU can use it,but all the books write it because GOTO statement is
 cotrary to  procedural programming.
 I had theachers that didn't accept  the homeworks with GOTO statements.
 FOR, REPEAT UNTIL , WHILE DO is produced instead of GOTO ,and they are
really more useful.

T1000

Other Threads