kids encyclopedia robot

goto facts for kids

Kids Encyclopedia Facts

GOTO is a special command used in some programming languages. Think of it like a "jump" instruction that tells a computer program to skip to a different part of the code. The word "GOTO" comes from "go to," which perfectly describes what it does!

Many older programming languages, like BASIC, used GOTO a lot. However, in newer languages, like Java, the GOTO command is not used, even though the word "goto" is kept as a reserved word. A reserved word is a special word that the programming language uses for its own commands, so you can't use it for other things, like naming a variable (a place to store information).

In the world of computer science, there's a big idea called the structured program theorem. This idea shows that you can write any computer program using special blocks of code called functions or methods. These blocks help keep the code organized and easy to understand, without needing to use GOTO commands to jump around. This theorem proved that GOTO isn't really necessary for writing programs.

How GOTO Commands Work

A GOTO command usually works with something called a label. A label is like a special sign or name that marks a specific spot in your computer code. When the program sees a GOTO command, it looks for that label and immediately jumps to the code right after it.

Here's a simple example of how it might look: GOTO START_OVER

In this example, the computer would jump to the part of the code that has the label START_OVER.

Sometimes, the GOTO command is used together with an if statement. An if statement checks if something is true. If it is, then the GOTO command will make the program jump. If it's not true, the program just continues normally.

For example: IF player_health_low THEN GOTO HEAL_PLAYER

This means: "If the player's health is low, then go to the part of the code that says HEAL_PLAYER." This way, the program only jumps when a certain condition is met.

Different programming languages have different rules about how and where you can use GOTO. For instance, in the C programming language, you can't use GOTO to jump from one function (a small, self-contained part of a program) into another.

Images for kids