Author Topic: Why never to use Goto.  (Read 23442 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Why never to use Goto.
« Reply #45 on: February 22, 2011, 11:01:13 pm »
This topic reminds me how I was forced to use Goto to create loops on the TI-81 due to lack of While/Repeat/For() O.O

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Why never to use Goto.
« Reply #46 on: February 24, 2011, 09:10:30 am »
Wow, the TI-81 was pretty limited. It's sad that TI-81 BASIC is still more capable than Nspire BASIC though. :P

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Why never to use Goto.
« Reply #47 on: February 24, 2011, 09:12:11 am »
At school, we have to write these basic programs with terribly unoptimized code. 
I know there are situations where the use of Lbl and Goto is inevitable, but all of those programs use the Goto and Lbl commands as like there is no tomorrow.

Yeah, even though my math teacher actual knows programming, he always, always uses IS<( / Goto instead of a simple For( loop. To keep things simple for everyone else, he says.




Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Why never to use Goto.
« Reply #48 on: February 24, 2011, 09:14:09 am »
Wow, I don't think I've ever used IS<(. O.O

Offline sjasogun1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 88
  • Rating: +8/-1
    • View Profile
Re: Why never to use Goto.
« Reply #49 on: February 24, 2011, 09:14:49 am »
Casio doesn't have repeat, so it's almost nessecary to have goto to restart the loop from several conditional statements inside of the loop without causing an error (which it will if you use Do-LpWhile or While-WhileEnd
Veni, vidi, cecidi
(I came, I saw, I fell down dead)
MSPAFORUMS: http://www.mspaforums.com/
HOMESTUCK: http://www.mspaintadventures.com/?s=6&p=001901

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Why never to use Goto.
« Reply #50 on: February 24, 2011, 09:23:37 am »
Wow, I don't think I've ever used IS<(. O.O

Me neither. IMHO For( is actually easier to understand :P




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Why never to use Goto.
« Reply #51 on: February 24, 2011, 12:28:13 pm »
This topic reminds me how I was forced to use Goto to create loops on the TI-81 due to lack of While/Repeat/For() O.O

Like:

Code: [Select]
0->A
Lbl L
DISP "TRY
A+1->A
If A<100
Then
Goto L
End

Stuff like this?

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Why never to use Goto.
« Reply #52 on: February 24, 2011, 12:34:15 pm »
This topic reminds me how I was forced to use Goto to create loops on the TI-81 due to lack of While/Repeat/For() O.O

Like:

Code: [Select]
0->A
Lbl L
DISP "TRY
A+1->A
If A<100
Then
Goto L
End

Stuff like this?
That reminds me of how I code loops in asm. otherwise in BASIC that's how I coded when I first started using the language.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Why never to use Goto.
« Reply #53 on: February 24, 2011, 02:23:41 pm »
This topic reminds me how I was forced to use Goto to create loops on the TI-81 due to lack of While/Repeat/For() O.O

Like:

Code: [Select]
0->A
Lbl L
DISP "TRY
A+1->A
If A<100
Then
Goto L
End

Stuff like this?

Probably with IS>(, I'd imagine.




Ashbad

  • Guest
Re: Why never to use Goto.
« Reply #54 on: February 24, 2011, 04:04:25 pm »
I love Java's break statement. It changed my life. Before, I would just goto out of the loop.

++

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Why never to use Goto.
« Reply #55 on: February 24, 2011, 04:23:57 pm »
I love Java's break statement. It changed my life. Before, I would just goto out of the loop.

++

Yep. I love the fact that Java doesn't support goto at all but has a break command for when you really need it.
« Last Edit: February 24, 2011, 04:24:07 pm by Deep Thought »




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Why never to use Goto.
« Reply #56 on: February 25, 2011, 03:20:15 am »
Casio doesn't have repeat, so it's almost nessecary to have goto to restart the loop from several conditional statements inside of the loop without causing an error (which it will if you use Do-LpWhile or While-WhileEnd
That sucks. X.x Does Goto cause memory leaks, though?
This topic reminds me how I was forced to use Goto to create loops on the TI-81 due to lack of While/Repeat/For() O.O

Like:

Code: [Select]
0->A
Lbl L
DISP "TRY
A+1->A
If A<100
Then
Goto L
End

Stuff like this?

Probably with IS>(, I'd imagine.
With IS>(, indeed. Here's an example:

0->U
Lbl 1
DispHome
DispGraph
IS>(U,5
Goto 1

That's the equivalent of:

For(Z,0,5
Disp
DispGraph
End

Or maybe it was For(Z,0,4, I dunno...
« Last Edit: February 25, 2011, 03:21:29 am by DJ_O »

Offline GreaseMonkey

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +3/-0
    • View Profile
Re: Why never to use Goto.
« Reply #57 on: February 25, 2011, 03:32:43 am »
Yes, Goto on a CASIO can leak:

Code: [Select]
Lbl 1
Do
Goto 1

Ends with a lovely Mem ERROR.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Why never to use Goto.
« Reply #58 on: February 25, 2011, 08:12:13 am »
Is that really a memory leak, though? You're telling the OS to continually allocate memory for Do statements. It's nothing more than infinite nesting. From what I understand, memory leaks are bugs in the code where the interpreter doesn't properly handle the memory allocations. Your example wouldn't count unless that program somehow terminates earlier than it should.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Why never to use Goto.
« Reply #59 on: February 25, 2011, 08:26:16 am »
Is that really a memory leak, though? You're telling the OS to continually allocate memory for Do statements. It's nothing more than infinite nesting. From what I understand, memory leaks are bugs in the code where the interpreter doesn't properly handle the memory allocations. Your example wouldn't count unless that program somehow terminates earlier than it should.
His program is an example of what has (incorrectly?) been called a memory leak for a long time in the TI community, but you are right.