Qbasicnews.com
November 14, 2019, 08:46:26 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Poll
Question: What do you think about using goto in your programs?
Always use GOTO - 0 (0%)
Often use GOTO - 3 (37.5%)
Somtimes use GOTO - 1 (12.5%)
Rarely use GOTO - 3 (37.5%)
Don't use GOTO - 1 (12.5%)
Total Voters: 8

Pages: [1]
  Print  
Author Topic: The forbidden GOTO  (Read 4009 times)
LPG
Member
*
Posts: 61

semper ubi sub ubi (always wear under wear)


« on: April 16, 2008, 01:44:40 AM »

Does anyone else use goto to write spaghetti programs like me?
Logged

WHILE RPG$ <> "complete" : make up silly excuses :WEND
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #1 on: April 16, 2008, 10:42:55 PM »

That's all hogwash really. Goto wouldn't even be there if you weren't supposed to use it!  Cheesy Of course, abuse is another story. A good rule of thumb is don't use goto to move backwards in your program, unless it's just a short hop, if you know what I mean.
Logged
Tia
Member
*
Posts: 37


« Reply #2 on: April 17, 2008, 09:55:41 PM »

I was taught not to use it but I really see no problem with using it.
Logged
wildcard
*.*
Administrator
__/--\__
*****
Posts: 2369



« Reply #3 on: April 18, 2008, 04:16:57 AM »

Using or not using GOTO is an age old debate. Simply put its best to not use it if you can as using it can make your program code a little harder to read but otherwise use it in small doses. Just remember there is usually more than one way to do code something.
Logged
LPG
Member
*
Posts: 61

semper ubi sub ubi (always wear under wear)


« Reply #4 on: April 19, 2008, 12:27:48 AM »

one of my spaghetti programs can be downloaded here:
http://practicalqbprogs.googlepages.com/peanuts
« Last Edit: April 30, 2008, 04:34:20 AM by LPG » Logged

WHILE RPG$ <> "complete" : make up silly excuses :WEND
zoasterboy
Guru
**
Posts: 295


Personal Text!


WWW
« Reply #5 on: April 22, 2008, 02:11:04 PM »

Jack of The Qbasic Station wrote a good article on this a while ago:

http://www.qbasicstation.com/index.php?c=t_article&a=10
Logged

-yah
Ralph
Ancient Guru
****
Posts: 544


« Reply #6 on: April 23, 2008, 03:38:34 PM »

Good reference, Zoasterboy!   I'm in agreement with it, too. 

One instance where I use the GOTO is when I am trouble shooting.  I'll enter this at the beginning of the code:
Code:

TEST = 0
TEST = 1
INPUT1 = 124 'just use any default value for the first INPUT statement
INPUT2 = 25   'default value for second INPUT statement
'etc.
Then, whenever the code is supposed to receive an INPUT statement, I'll add, just before it:
Code:
IF TEST = 1 THEN GOTO SKIP1
and I'll conclude that part of code with:
Code:
SKIP1:
Now, I can run my code over and over, without having to stop and enter something at each INPUT statement, letting me quickly get to the problem(s) I am trying to find and debug. 

Once the program runs fine, I either remark out the line,
TEST = 1
which allows me to further trouble shoot easily in the future, or, if I'm very sure I will not have to do any more debugging,  I will delete both "TEST =" lines, and all the pertinent GOTO... and SKIP1:, SKIP2:, etc. labels.
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!