Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ () — Coherent 3.1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought


goto                        C Keyword                        goto




Unconditionally jump within a function


A goto command  jumps to the area of the  program introduced by a
label.  A program can goto only within a function; to jump across
function  boundaries,  you  must  use  the functions  setjmp  and
longjmp.

In the context of C programming,  the most common use for goto is
to exit from a control block or go to the top of a control block.
It  is  used  most often  to  write  ``ripcord'' routines,  i.e.,
routines that are executed  when an major error occurs too deeply
within  a function  for the  program  to disentangle  itself cor-
rectly.  Note that in most instances, goto is a bad solution to a
problem that can be better solved by structured programming.

***** Example *****

The following example demonstrates how to use goto.


#include <stdio.h>



main()
{
        char line[80];



getline:
        printf("Enter line: ");
        fflush(stdout);
        gets(line);



/* a series of tests often is best done with goto's */
        if (*line == 'x') {
                printf("Bad line\n");
                goto getline;
        } else if (*line == 'y') {
                printf("Try again\n");
                goto getline;
        } else if (*line == 'q')
                goto goodbye;
        else
                goto getline;







COHERENT Lexicon                                           Page 1



goto                        C Keyword                        goto



goodbye:
        printf("Goodbye.\n");
        exit(0);
}


***** See Also *****

C keywords

***** Notes *****

The C  Programming Language describes  goto as ``infinitely-abus-
able'': caveat utilitor.











































COHERENT Lexicon                                           Page 2


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026