HP C A.06.05 Reference Manual
Statements
goto
Chapter 6166
goto
Syntax
goto
label
;
Arguments
label
This is a label or tag associated with an executable statement.
Description
The purpose of the goto statement is to enable program control to jump to some other
statement. The destination statement is identiļ¬ed by a statement label, which is just a name
followed by a colon. The label must be in the same function as the goto statement that
references it.
Few programming statements have produced as much debate as the goto statement. The
goto statement is necessary in more rudimentary programming languages, but its use in
high-level languages is generally frowned upon. Nevertheless, most high-level languages,
including C, contain a goto statement for those rare situations where it can't be avoided.
With deeply nested logic there are times when it is cleaner and simpler to bail out with one
goto rather than backing out of the nested statements. The most common and accepted use
for a goto is to handle an extraordinary error condition.
Example
The following example shows a goto that can easily be avoided by using the while loop, and
also shows an illegal goto:
/* Program name is "goto_example". This program finds the
* circumference and area of a circle when the user gives
* the circle's radius.
*/
#include <stdio.h>
#define PI 3.14159
int main(void)
{
float cir, radius, area;