Using GOTO statements.

          Now that we have covered IF-THEN statements we can make them more usefull by using GOTO statements. GOTO statements allow the programmer to transfer jump from one portion of the program to a different one. This is so that you can 'branch' out into different sections of the program if necessary. The general form of GOTO is this:
        GOTO label
where label can be anything you want, including numbers so 10 is a perfectly good label. What the label is used for is to tell the interpreter where to go. So if you say GOTO 10 then the interpreter will look for a line starting with 10:. Notice that the actuall label must have a colon after it, a refrence to that label as in GOTO 10 doesn't. Here is an Example:

        INPUT "what is your age"; age%
        IF age% < 10 THEN GOTO 10
        IF age% >= 10 AND age% < 20 THEN GOTO 20
        IF age% >= 20 AND age% < 30 THEN GOTO 30
        IF age% >= 30 AND age% < 40 THEN GOTO 40
        IF age% >= 40 THEN GOTO 50

        10: PRINT "You are too young!"
        END

        20: PRINT "Still, not old enough!"
        END

        30: PRINT "So How's it feel to be in your 20's?"
        END

        40: PRINT "Just Think soon your kids will be able to drive!"
        END

        50: PRINT "Now You're over the Hill!!!"
        END

Output:
        what is your age? 23
        So How's it feel to be in your 20's?

        As you can see, this method of code selection is much nicer than the IF-THEN blocks, however, don't count IF-THEN blocks out, becuase they come in very handy, especially for small pieces of code. I recommend that you try this example, and play with it until you get comfortable with the syntax of the IF-THEN and GOTO.
        As nice as they look, GOTOs have a lot of problems, one of the major problems with GOTO's is that they offer no way to get back to the main part of the program. This can be solved by making labels and using GOTOs to take you back to where you came from, but that also gets pretty messy. There is a much nicer soloution to this, that is using GOSUBs instead of GOTOs which do allow a method of getting back to where you came from.
        Other problems with GOTOs are, after awhile when your program starts becoming large, it starts getting hard to remember what is going on, because GOTOs allow unrestricted jumps to anywhere. Also, your programs become impossible to read. Teachers tend to tell the students not to use GOTO's because it is bad programming practice, well, I'm going to tell you the same thing. But In addition to that I'm also going to say that it is okay to use GOTO's as long as you keep in mind that there is probably a better nicer way of doing it, but it's all up to you.

    Back         Tutorial Part 1         Next