The Goto statement in FoxPro

It's been a long time since Edsger Dijkstra wrote his famous 1968 letter "Goto Statement Considered Harmful" and many languages no longer even have such a jump command. FoxPro does have a Goto but it's not a program control command. It's a table navigation command and it moves the record pointer to the record number specified. The command:

Goto 12

will move the record pointer to record number 12. This command is useful in small record sets but can be slow in a large table and it goes against the spirit of a relational database. When you use it you assume that you can rely on the absolute position of a record in a data set. You also restrict yourself to using native FoxPro data tables.

Goto Statement Still Considered Harmful

This command was useful in FoxBase on small, single-user systems but it has the potential to introduce some very awkward intermittent bugs on larger systems. Visual FoxPro still has the command but it should be considered as being included for backwards compatibility only.

Worse than "Harmful"

The Goto command can be shortened to Go but even this is optional. All that you have to do is state the record number:

12

on its own will move the record pointer to record 12. This is an idiosyncracy of the language which really should not be used in any production code.


Introduction | Environment | Project | Tables | Forms | Navigation | Executable

MS Access technical tips

Visual FoxPro technical tips

General Tips

 

More tips from Alvechurch Data

Visual FoxPro Tutorial - If ... Else ... EndIf

Using If EndIf to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Navigation

Navigating between records in Visual FoxPro

Read More

Visual FoxPro Tutorial - Scan ... EndScan loop

Using a scan loop to control program flow in Visual FoxPro

Read More

Visual FoxPro Tutorial - Variables

Using variables in Visual FoxPro

Read More

Visual FoxPro Tutorial - Program control

Syntax for program control structures in Visual FOxPro

Read More