0% found this document useful (0 votes)
71 views2 pages

IV. Go To Statement.: Goto Goto

The document discusses the goto statement in C programming. It states that the goto statement allows unconditional branching to another part of the program but should only be used sparingly as C is a structured language. The goto syntax transfers control to a labeled statement using the label name. Proper use of conditionals and loops is preferable to overuse of gotos which can harm program structure and logic.

Uploaded by

srivatsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views2 pages

IV. Go To Statement.: Goto Goto

The document discusses the goto statement in C programming. It states that the goto statement allows unconditional branching to another part of the program but should only be used sparingly as C is a structured language. The goto syntax transfers control to a labeled statement using the label name. Proper use of conditionals and loops is preferable to overuse of gotos which can harm program structure and logic.

Uploaded by

srivatsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

B.

Sc I Year / II Semester
UNIT – I  ‘C’ Fundamentals, Tokens, Control and Decision Making Statements
IV. GO TO STATEMENT.
C has goto statement but one must ensure not to use too much of goto statement in their program
because its functionality is limited and it is only recommended as a last resort if structured
solutions are much more complicated.

First let us understand the gotostatement, its syntax and functionality.

The goto is a unconditional branching statement used to transfer control of the program from one
statement to another.

Syntax of goto statement is:

goto namel;
…………. ………….
…………. ………….
…………. ………….
name1:
Statement;

Here in goto,
name1 mentioned identifies the place where the branch is to be made.
name1 is a valid variable name followed by a colon.
name1 is placed immediately before the statement where the control is to be transformed.

A program may contain several goto statements. The names mentioned in goto must be unique
for branching.

Control can be transferred out of or within a compound statement and control can be transferred
to the beginning of a compound statement. However the control cannot be transferred into a
compound statement.

One must take care not to use too much of goto statements in their program or in other words use
it only when needed. This is because C being a highly structured language one must take care not
to use too much of these unconditional goto branching statements. The goto statement is
discouraged in C, because it alters the sequential flow of logic that is the characteristic of C
language. This word is redundant in C and encourages poor programming style.

CHP 5(‘C’ LANG. DECISION M S) Page 1


B.Sc I Year / II Semester
UNIT – I  ‘C’ Fundamentals, Tokens, Control and Decision Making Statements

Fig: Forward Jump goto Statement Fig: goto Statement

Fig: Backward Jump goto Statement

#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf("Enter a and b value");
scanf("%d%d",&a,&b);
if(a>b)
goto pos;
else
goto neg;
pos:;
c=a-b;
printf("This the case where a is greater than b");
printf("\nThe a value is %d and b value is %d",a,b);
printf("\nThe subtracted result is %d",c);
goto out;
neg:;
d=b-a;
printf("This the case where b is greater than a");
printf("\nThe a value is %d and b value is %d",a,b);
printf("\nThe subtracted result is %d",d);
out:
getch();
}

CHP 5(‘C’ LANG. DECISION M S) Page 2

You might also like