Quote:Some of my friends have said that GOTO is another one of those useful commands that my teacher never botherd to tell us about. So I'm thinking of using it in my final project, but I don't know what it is. :-?
Can somebody explain what GOTO does?
BLADER,
In order to answer your question, I'm going to give you a simple explanation of how a computer executes instructions.
When a computer program is loaded into computer memory, it is assigned a starting address. This address is the first instruction to be executed.
It will perform the first instruction, and continue to the next instruction, unless the instructon is a GOTO, which in machine language is called a JUMP, TRANSFER, or BRANCH.
This means that the computer will continue executing consecutive instructions until it encounters the equivalent of a GOTO.
When a GOTO is encountered, it does not execute the next instruction, but begins executing the instruction at the address contained in the GOTO instruction.
In QB, the GOTO statement or instruction is always unconditional, that is, GOTO right now, no matter what. In machine language it can be conditional, like JUMP IF ZERO TO SAME.
We can do the same thing in QB by using an IF and a GOTO:
IF A = B THEN GOTO SAME
Actually, in assembler, there are also two parts to the above JUMP IF ZERO example. First, you would subtract B from A, and then do the JUMP IF ZERO.
In QB, there are other statements besides GOTO which allow you to change the sequence of instruction execution. These are "loop control" statements, which basically will continue to execute a set of instructions in a loop until a given condition is met. Some of these "loop control" statments are:
FOR ... NEXT
DO WHILE... LOOP
WHILE ... WEND
Another form of statments which change the sequence of instruction execution are the SELECT CASE ... CASE ... END SELECT.
If your program did not have the capability to do the equivalent of a GOTO, it would start at the beginning, execute all the instructions once, and exit after the last instruction. This is not what you normally want. You need to control the flow and execution of the instructions in your program. Any form of a GOTO will give you this ability.
*****