Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About using GOTO . . .
#11
what you could have done is just return back to a main loop and have a trigger value then say where to go next. But that takes longer to program than a simple GOTO.

GOTOs are used heavily in good genetic programs, too. Smile I made a poker player for my class last semester that only had IFs and GOTOs. With GOTOs it is possible to simulate very complicated structures without explicitly saying so. And this is good for genetic programs because it makes both interpretation of the programs and breeding easy. Smile
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#12
using GOSUB statements, you were doing something wrong. The only (legitimate) way you can push on stack space with GOSUB and RETURN is to have a lot of nested subroutines, and I doubt that QB will let you have that many nested subroutines. Merely calling the subroutine repeatedly shouldn't cause a problem with stack space. QB moves the "stack pointer" back down after returning from the subroutine. (The use you gave of GOTO statements is the ONE and only way of using them that I've ever been able to disagree with. Smile )
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#13
I haven't used GOTO for about 5 years. Qbasic eliminated line numbers, so suddenly you needed labels, which look terrible. No other (serious) programming language includes an equivalent 'GOTO' statement. How can you represent it in a flowchart? Is it a branch or a loop?

Need a conditional loop? Use DO LOOP UNTIL or DO UNTIL LOOP
Need a subroutine or branch? Use GOSUB, or better yet an actual SUB.

Poor style, because you can't indent it properly:
Code:
DO 'Animation Loop
    PUT (xloc, yloc), mainchar, PSET
    key$ = INKEY$
    SELECT CASE key$
       CASE Up
         yloc = yloc - 1
       CASE Down
         yloc = yloc + 1
       ...
    END SELECT
    ...
LOOP UNTIL quittag
If you do the same thing with a GOTO at the bottom, because it's a branch and not a loop, you can't really indent, so you get this instead:
Code:
oops: 'Animation Loop
PUT (xloc, yloc), mainchar, PSET
key$ = INKEY$
SELECT CASE key$
   CASE Up
     yloc = yloc - 1
   CASE Down
     yloc = yloc + 1
   ...
END SELECT
...
IF NOT quittag THEN GOTO oops:
It looks fine, but once you have those 'goto loops' nested for drawing particles or enemies or whatever, you'll end up with a jolly mess.

GOTO and GOSUB were made obscelete by QB. They were included for compatibily's sake.
Reply
#14
Quote:No other (serious) programming language includes an equivalent 'GOTO' statement.

Not true. C language has GOTO.

Code:
// Horrid, nonsense, just-for-syntax-purpose example

int test(int a)
{
   if (a==7) goto hello;
   return 2;
hello:
   return 3;
}

And it is util sometimes. Imagine yourself inside 27 nested and mixed DO:LOOPs / WHILE:WEND / FOR:NEXT... If you wanna exit, the fastest sollution posible is place a GOTO pointing outside. Of course it looks ugly and you can do it with exit conditions in every loop, but it is way faster. The linux kernel itself is full of GOTOs to achieve both more efficience and less space.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
Quote: Poor style, because you can't indent it properly
I don't indent. You can't read complicated indented code.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#16
"GOTO and GOSUB were made obscelete by QB. They were included for compatibily's sake."

They were included because they're a fundamental part of the Basic language. I wouldn't consider using anything that called itself a version of Basic if it didn't include those statements. (I probably wouldn't use it if it didn't call itself a version of Basic.) If QB had made them obsolete, it wouldn't have them as part of its keyword set. (And if you think QB is the first programming tool to introduce such enyucked things as IF/THEN constructs, you're really myopic.)

(And I'm glad to hear I'm not the only one who hates indented code. Smile )
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#17
I do indent. It is easier for me. Should it be a matter of anyone.

But QB does not have GOTO/GOSUB, like Glenn said, only for backwards compatibility. In fact, some programming techniques used in QB 3.0, for example, don't work in QB4.5 / Qbasic 1.x at least you change them a bit, for example RANDOM files.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#18
it's your intent to indent?


(Ah. Finally got a bad pun out of my system.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#19
Quote:it's your intent to indent?


(Ah. Finally got a bad pun out of my system.)

Hahahahahaha!!!

"Does this look indented"??? Sum 41 or 42
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#20
Well, it looks like using GOTO is more a matter of preference than anything else.

BTW, I love the new "labeling" style of programming over the old numbering system. Makes moving blocks around much easier. Also, I like indenting. I think it makes it a lot easier to read code.

But, regardless, this has benn an interesting thread. Smile

Dex
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)