Qbasicnews.com

Full Version: What does GOTO do?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
GOTO's are a mixed bag of personal programming preferences...

I've been using them lately as a slick way to incorporate variable pointers in QB.

Laters!

Ps...

A brand new QB game is coming soon! I will upload a demo of it in a few days Big Grin
It's a Stratego clone, with drag -n- drop game piece movement and a nice mouse driven gui!
I don't know about everyone else, but when I went to school, GOTO only managed to do one thing...take 5 points off my average everytime I used it LOL.....makes sorta persuating to NOT use it.

It's bad practice...except in the very few cases where there's no other way around it (which are very few) uses subs and functions instead and call those instead of goto :-)
I can understand instructors and others being ademantly against the totally indiscrimanate use of GOTOs that make code next to impossible to follow or understand!

But, I believe that using that as a pretext for punisment is wrong! It should be clearly explained, as anything that works should. Then the "spaggetti" code problem should be strongly driven home by giving the student a homework problem where a section of code with a "spaggetti"-of-GOTOs exists, as an illustration of what NOT to do. But, any difficult and obscure coding without documentation has a similar problem.

If one uses GOTOs sparingly, and with proper documentation, I, personally, see nothing wrong with using GOTOs.

Anyway, that's my very personal opinion!
Here we go again... :roll:


:lol:


Seriously though...

Ponder this. Say you have a loop that assigns random values to an array of circles ©

Code:
For i = 1 to ubound(C)
    RandomVals:
    C(i).X=Int(rnd*MWidth)
    C(i).Y=Int(rnd*MHeight)
    C(i).Radius = Int(rnd*25)

    For i2=1 to ubound(C)
        If i<>i2 Then
            Dist=Distance( C(i), C(i2) )
            If Dist<= C(i).Radius+C(i2).Radius Then GOTO RandomVals
        End If
    Next
Next

I don't think it's bad practice to use it in that context. It just gets out of control when you have 500 different goto's in a single program. :lol:
using it in that context is thee only way.
The last time I used goto was shortly before I started attending some programming classes at a community college. Since then I've never found a need to use goto. In fact I believe that if you have to, then most of the time something is wrong with the design of the code. :wink:

There are times when it probably would be okay to go with gotos. The only one I can think of is when your program needs extra speed and using goto over other methods achieves a modest improvement.
There is another reason to use GOTO: when using ON ERROR statements in QB to help debug the program. Wink

Anonymous

Code:
For i = 1 to ubound(C)
   itsallgood = 0

    do

    C(i).X=Int(rnd*MWidth)
    C(i).Y=Int(rnd*MHeight)
    C(i).Radius = Int(rnd*25)

    For i2=1 to ubound(C)
        If i<>i2 Then
            Dist=Distance( C(i), C(i2) )

            If Dist<= C(i).Radius+C(i2).Radius Then
              itsallgood = 0
              exit for
            else
              itsallgood = -1
            end if

        End If
    Next

    loop until itsallgood

Next

think that'll work, not tested

edit: but is it too complicateD?
Now, why whould Chaos' 19 lines of code be "better" than Dr_Davenstein's 12? Certainly more complexity has been added with the additional code?

Why not accept that all is relative, that "The use of GOTOs in coding is bad" should be changed to "Abusive use of GOTOs, just as abusive use of ANY coding practice, should be strongly discouraged" ?
i can't belive people are still responding to this thread.
yes i know what i just did.

GOTO's are fine in moderation.
Pages: 1 2 3 4 5