Re: TIB: Old topic-Goto/Lbl statements


[Prev][Next][Index][Thread]

Re: TIB: Old topic-Goto/Lbl statements




Well, I'm pretty sure you could use a loop but this would really be
one of the rare cases where a 'Goto' is the best way to go. There is
no need for speed, and anyone can figure the code out...

How to implement a loop

Repeat FlagVar
..
..
..
Ask player if he wants to play again
If answer is no, FlagVar = 1
End

Simple, but a goto is better... for once!

The problem with gotos is that people tend to use them for loops
instead of For,While, Repeat or they jump from one spot to another,
doing maybe 10 lines at a time, wich slows everything down and makes
the prog impossible to understand

Philipp Keller

----- Original Message -----
From: Grant Winney <cosmo70@hotmail.com>
To: <ti-basic@lists.ticalc.org>
Sent: 21 May 1999 20:51
Subject: Re: TIB: Old topic-Goto/Lbl statements


>
> Thanks for responding, Adam.  I didn't realize the goto command was
such a
> big deal. (Shows what I know!)  However, I haven't taken any
programming
> classes yet, so I guess I'll find out.
>
> I couldn't think of any sample code to put in here, but I just
wanted to say
> thanks for taking the time to write all that.  Can anyone else think
up some
> code, rich in 'goto's, so that I could have an example of how it
could be
> stated otherwise?
>
> Actually, what if you have a long game - at the end of which you
might give
> the user a choice to either 'play again' or 'quit'.  If the user
chooses
> 'play again', the code might say GOTO TOP, where the first line of
code in
> the program is LBL TOP.  To me, this seems easiest (maybe it is),
but how
> could a programmer get around that 'goto' command?
>
> -Grant Winney
> cosmo70@hotmail.com
>
>
> Original message:
>
> >From: Adam Davis <adavis@baladyne.com>
> >Subject: Re: TIB: Old topic-Goto/Lbl statements
> >Date: Fri, 21 May 1999 13:12:34 -0400
> >
> >Code which utilizes GOTO is referred to as spaghetti code.  It is
bad
> >only if it ever has to be modified, then it becomes almost
impossible
> >for a coder to decode someone's spaghetti code, because they have
to try
> >and follow each goto around the program, instead of simply viewing
the
> >code from top to bottom.
> >
> >Instead of jumping all over the program with GOTOs, one should use
> >while/for loops, and if then else endif constructs.
> >
> >All of the looping and test constructs generally take less cpu time
than
> >a goto.
> >
> >In theory it is possible to make any program without a single goto.
In
> >practice it is not always the most efficient way, but it rarely
happens
> >that a goto is *needed*.
> >
> >Subroutines are very important as well, but are not supported as
such on
> >the TI.  It's best to make often used parts of the program
available in
> >a seperate program.
> >
> >Using GOTOs is frowned on, as you will find out in "structered
> >programming" books and courses.  As always, assembly is completely
> >different, and different 'rules' apply there.
> >
> >Give me a simple program that uses goto, and I can show you how it
would
> >appear were it programmed without gotos.
> >
> >-Adam
>
>
> _______________________________________________________________
> Get Free Email and Do More On The Web. Visit http://www.msn.com
>



References: