HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 6 Statements

The goto Statement

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The goto statement transfers control to a labeled statement that is within the scope of the current function.

Syntax

goto identifier;

Description

The goto statement causes an unconditional branch to the named label in the current function. Because you can use goto statements to jump to any statement that can be labeled, the potential for their abuse is great. For example, you can branch into loop bodies and enter blocks at points other than the head of the block. This can cause problems if you attempt to access variables initialized at the beginning of the block. Generally, you should avoid using goto statements because they disturb the structure of the program, making it difficult to understand. A common use of goto statements in C is to exit from several levels of nested blocks when detecting an error.